1
0

media_controller_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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, visibility: :direct)
  23. media_attachment = Fabricate(:media_attachment, status: status)
  24. get :show, params: { id: media_attachment.to_param }
  25. expect(response).to have_http_status(404)
  26. end
  27. end
  28. end