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

39 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe MediaController do
  4. render_views
  5. describe '#show' do
  6. it 'redirects to the file url when attached to a status' do
  7. status = Fabricate(:status)
  8. media_attachment = Fabricate(:media_attachment, status: status)
  9. get :show, params: { id: media_attachment.to_param }
  10. expect(response).to redirect_to(media_attachment.file.url(:original))
  11. end
  12. it 'responds with missing when there is not an attached status' do
  13. media_attachment = Fabricate(:media_attachment, status: nil)
  14. get :show, params: { id: media_attachment.to_param }
  15. expect(response).to have_http_status(404)
  16. end
  17. it 'raises when shortcode cant be found' do
  18. get :show, params: { id: 'missing' }
  19. expect(response).to have_http_status(404)
  20. end
  21. it 'raises when not permitted to view' do
  22. status = Fabricate(:status)
  23. media_attachment = Fabricate(:media_attachment, status: status)
  24. allow_any_instance_of(MediaController).to receive(:authorize).and_raise(ActiveRecord::RecordNotFound)
  25. get :show, params: { id: media_attachment.to_param }
  26. expect(response).to have_http_status(404)
  27. end
  28. end
  29. end