]>
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') }
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('files/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('files/attachment.jpg', 'image/jpeg') }
32 it
'returns http 422' do
33 expect(response
).to
have_http_status(:error)
38 context
'image/jpeg' do
40 post
:create, params
: { file
: fixture_file_upload('files/attachment.jpg', 'image/jpeg') }
43 it
'returns http success' do
44 expect(response
).to
have_http_status(:success)
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('files/attachment.gif', 'image/gif') }
65 it
'returns http success' do
66 expect(response
).to
have_http_status(:success)
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('files/attachment.webm', 'video/webm') }
87 xit
'returns http success' do
88 expect(response
).to
have_http_status(:success)
91 xit
'creates a media attachment' do
92 expect(MediaAttachment
.first
).to_not be_nil
95 xit
'uploads a file' do
96 expect(MediaAttachment
.first
).to
have_attached_file(:file)
99 xit
'returns media ID in JSON' do
100 expect(body_as_json
[:id]).to eq MediaAttachment
.first
.id
.to_s
This page took 0.084409 seconds and 4 git commands to generate.