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.

42 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe MediaProxyController do
  4. render_views
  5. before do
  6. stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
  7. end
  8. describe '#show' do
  9. it 'redirects when attached to a status' do
  10. status = Fabricate(:status)
  11. media_attachment = Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png')
  12. get :show, params: { id: media_attachment.id }
  13. expect(response).to have_http_status(302)
  14. end
  15. it 'responds with missing when there is not an attached status' do
  16. media_attachment = Fabricate(:media_attachment, status: nil, remote_url: 'http://example.com/attachment.png')
  17. get :show, params: { id: media_attachment.id }
  18. expect(response).to have_http_status(404)
  19. end
  20. it 'raises when id cant be found' do
  21. get :show, params: { id: 'missing' }
  22. expect(response).to have_http_status(404)
  23. end
  24. it 'raises when not permitted to view' do
  25. status = Fabricate(:status, visibility: :direct)
  26. media_attachment = Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png')
  27. get :show, params: { id: media_attachment.id }
  28. expect(response).to have_http_status(404)
  29. end
  30. end
  31. end