闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::MediaController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { double acceptable?: true, resource_owner_id: user.id }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'POST #create' do
  10. context 'image/jpeg' do
  11. before do
  12. post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') }
  13. end
  14. it 'returns http success' do
  15. expect(response).to have_http_status(:success)
  16. end
  17. it 'creates a media attachment' do
  18. expect(MediaAttachment.first).to_not be_nil
  19. end
  20. it 'uploads a file' do
  21. expect(MediaAttachment.first).to have_attached_file(:file)
  22. end
  23. it 'returns media ID in JSON' do
  24. expect(body_as_json[:id]).to eq MediaAttachment.first.id
  25. end
  26. end
  27. context 'video/webm' do
  28. before do
  29. post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') }
  30. end
  31. xit 'returns http success' do
  32. expect(response).to have_http_status(:success)
  33. end
  34. xit 'creates a media attachment' do
  35. expect(MediaAttachment.first).to_not be_nil
  36. end
  37. xit 'uploads a file' do
  38. expect(MediaAttachment.first).to have_attached_file(:file)
  39. end
  40. xit 'returns media ID in JSON' do
  41. expect(body_as_json[:id]).to eq MediaAttachment.first.id
  42. end
  43. end
  44. end
  45. end