]>
cat aescling's git repositories - mastodon.git/blob - spec/controllers/api/v1/media_controller_spec.rb
3 RSpec
.describe Api
::V1::MediaController, type
: :controller do
6 let(:user) { Fabricate(:user, account
: Fabricate(:account, username
: 'alice')) }
7 let(:token) { Fabricate(:accessible_access_token, resource_owner_id
: user
.id
, scopes
: 'write:media') }
10 allow(controller
).to
receive(:doorkeeper_token) { token
}
13 describe
'POST #create' do
14 describe
'with paperclip errors' do
15 context
'when imagemagick cant identify the file type' do
17 expect_any_instance_of(Account
).to
receive_message_chain(:media_attachments, :create!
).and_raise(Paperclip
::Errors::NotIdentifiedByImageMagickError)
18 post
:create, params
: { file
: fixture_file_upload('attachment.jpg', 'image/jpeg') }
21 it
'returns http 422' do
22 expect(response
).to
have_http_status(:unprocessable_entity)
26 context
'when there is a generic error' do
28 expect_any_instance_of(Account
).to
receive_message_chain(:media_attachments, :create!
).and_raise(Paperclip
::Error)
29 post
:create, params
: { file
: fixture_file_upload('attachment.jpg', 'image/jpeg') }
32 it
'returns http 422' do
33 expect(response
).to
have_http_status(500)
38 context
'image/jpeg' do
40 post
:create, params
: { file
: fixture_file_upload('attachment.jpg', 'image/jpeg') }
43 it
'returns http success' do
44 expect(response
).to
have_http_status(200)
47 it
'creates a media attachment' do
48 expect(MediaAttachment
.first
).to_not be_nil
51 it
'uploads a file' do
52 expect(MediaAttachment
.first
).to
have_attached_file(:file)
55 it
'returns media ID in JSON' do
56 expect(body_as_json
[:id]).to eq MediaAttachment
.first
.id
.to_s
60 context
'image/gif' do
62 post
:create, params
: { file
: fixture_file_upload('attachment.gif', 'image/gif') }
65 it
'returns http success' do
66 expect(response
).to
have_http_status(200)
69 it
'creates a media attachment' do
70 expect(MediaAttachment
.first
).to_not be_nil
73 it
'uploads a file' do
74 expect(MediaAttachment
.first
).to
have_attached_file(:file)
77 it
'returns media ID in JSON' do
78 expect(body_as_json
[:id]).to eq MediaAttachment
.first
.id
.to_s
82 context
'video/webm' do
84 post
:create, params
: { file
: fixture_file_upload('attachment.webm', 'video/webm') }
88 # returns http success
89 expect(response
).to
have_http_status(200)
91 # creates a media attachment
92 expect(MediaAttachment
.first
).to_not be_nil
95 expect(MediaAttachment
.first
).to
have_attached_file(:file)
97 # returns media ID in JSON
98 expect(body_as_json
[:id]).to eq MediaAttachment
.first
.id
.to_s
103 describe
'PUT #update' do
104 context
'when somebody else\'s' do
105 let(:media) { Fabricate(:media_attachment, status
: nil) }
107 it
'returns http not found' do
108 put
:update, params
: { id
: media
.id
, description
: 'Lorem ipsum!!!
' }
109 expect(response).to have_http_status(:not_found)
113 context 'when not attached to a status
' do
114 let(:media) { Fabricate(:media_attachment, status: nil, account: user.account) }
116 it 'updates the description
' do
117 put :update, params: { id: media.id, description: 'Lorem ipsum!!!
' }
118 expect(media.reload.description).to eq 'Lorem ipsum!!!
'
122 context 'when attached to a status
' do
123 let(:media) { Fabricate(:media_attachment, status: Fabricate(:status), account: user.account) }
125 it 'returns http
not found
' do
126 put :update, params: { id: media.id, description: 'Lorem ipsum!!!
' }
127 expect(response).to have_http_status(:not_found)
This page took 0.131323 seconds and 4 git commands to generate.