闭社主体 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.

81 lines
2.1 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 'image/gif' do
  28. before do
  29. post :create, params: { file: fixture_file_upload('files/attachment.gif', 'image/gif') }
  30. end
  31. it 'returns http success' do
  32. expect(response).to have_http_status(:success)
  33. end
  34. it 'creates a media attachment' do
  35. expect(MediaAttachment.first).to_not be_nil
  36. end
  37. it 'uploads a file' do
  38. expect(MediaAttachment.first).to have_attached_file(:file)
  39. end
  40. it 'returns media ID in JSON' do
  41. expect(body_as_json[:id]).to eq MediaAttachment.first.id
  42. end
  43. end
  44. context 'video/webm' do
  45. before do
  46. post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') }
  47. end
  48. xit 'returns http success' do
  49. expect(response).to have_http_status(:success)
  50. end
  51. xit 'creates a media attachment' do
  52. expect(MediaAttachment.first).to_not be_nil
  53. end
  54. xit 'uploads a file' do
  55. expect(MediaAttachment.first).to have_attached_file(:file)
  56. end
  57. xit 'returns media ID in JSON' do
  58. expect(body_as_json[:id]).to eq MediaAttachment.first.id
  59. end
  60. end
  61. end
  62. end