]> cat aescling's git repositories - mastodon.git/blob - spec/controllers/api/v1/media_controller_spec.rb
Change IDs to strings rather than numbers in API JSON output (#5019)
[mastodon.git] / spec / controllers / api / v1 / media_controller_spec.rb
1 require 'rails_helper'
2
3 RSpec.describe Api::V1::MediaController, type: :controller do
4 render_views
5
6 let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
7 let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write') }
8
9 before do
10 allow(controller).to receive(:doorkeeper_token) { token }
11 end
12
13 describe 'POST #create' do
14 describe 'with paperclip errors' do
15 context 'when imagemagick cant identify the file type' do
16 before 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') }
19 end
20
21 it 'returns http 422' do
22 expect(response).to have_http_status(:unprocessable_entity)
23 end
24 end
25
26 context 'when there is a generic error' do
27 before 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') }
30 end
31
32 it 'returns http 422' do
33 expect(response).to have_http_status(:error)
34 end
35 end
36 end
37
38 context 'image/jpeg' do
39 before do
40 post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') }
41 end
42
43 it 'returns http success' do
44 expect(response).to have_http_status(:success)
45 end
46
47 it 'creates a media attachment' do
48 expect(MediaAttachment.first).to_not be_nil
49 end
50
51 it 'uploads a file' do
52 expect(MediaAttachment.first).to have_attached_file(:file)
53 end
54
55 it 'returns media ID in JSON' do
56 expect(body_as_json[:id]).to eq MediaAttachment.first.id.to_s
57 end
58 end
59
60 context 'image/gif' do
61 before do
62 post :create, params: { file: fixture_file_upload('files/attachment.gif', 'image/gif') }
63 end
64
65 it 'returns http success' do
66 expect(response).to have_http_status(:success)
67 end
68
69 it 'creates a media attachment' do
70 expect(MediaAttachment.first).to_not be_nil
71 end
72
73 it 'uploads a file' do
74 expect(MediaAttachment.first).to have_attached_file(:file)
75 end
76
77 it 'returns media ID in JSON' do
78 expect(body_as_json[:id]).to eq MediaAttachment.first.id.to_s
79 end
80 end
81
82 context 'video/webm' do
83 before do
84 post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') }
85 end
86
87 xit 'returns http success' do
88 expect(response).to have_http_status(:success)
89 end
90
91 xit 'creates a media attachment' do
92 expect(MediaAttachment.first).to_not be_nil
93 end
94
95 xit 'uploads a file' do
96 expect(MediaAttachment.first).to have_attached_file(:file)
97 end
98
99 xit 'returns media ID in JSON' do
100 expect(body_as_json[:id]).to eq MediaAttachment.first.id.to_s
101 end
102 end
103 end
104 end
This page took 0.084409 seconds and 4 git commands to generate.