1
0

media_controller_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe MediaController do
  4. render_views
  5. describe '#show' do
  6. it 'raises when shortcode cant be found' do
  7. get :show, params: { id: 'missing' }
  8. expect(response).to have_http_status(404)
  9. end
  10. context 'when the media attachment has a shortcode' do
  11. it 'redirects to the file url when attached to a status' do
  12. status = Fabricate(:status)
  13. media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'OI6IgDzG-nYTqvDQ994')
  14. get :show, params: { id: media_attachment.to_param }
  15. expect(response).to redirect_to(media_attachment.file.url(:original))
  16. end
  17. it 'responds with missing when there is not an attached status' do
  18. media_attachment = Fabricate(:media_attachment, status: nil, shortcode: 'OI6IgDzG-nYTqvDQ994')
  19. get :show, params: { id: media_attachment.to_param }
  20. expect(response).to have_http_status(404)
  21. end
  22. it 'raises when not permitted to view' do
  23. status = Fabricate(:status, visibility: :direct)
  24. media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'OI6IgDzG-nYTqvDQ994')
  25. get :show, params: { id: media_attachment.to_param }
  26. expect(response).to have_http_status(404)
  27. end
  28. end
  29. context 'when the media attachment has no shortcode' do
  30. it 'redirects to the file url when attached to a status' do
  31. status = Fabricate(:status)
  32. media_attachment = Fabricate(:media_attachment, status: status)
  33. get :show, params: { id: media_attachment.to_param }
  34. expect(response).to redirect_to(media_attachment.file.url(:original))
  35. end
  36. it 'responds with missing when there is not an attached status' do
  37. media_attachment = Fabricate(:media_attachment, status: nil)
  38. get :show, params: { id: media_attachment.to_param }
  39. expect(response).to have_http_status(404)
  40. end
  41. it 'raises when not permitted to view' do
  42. status = Fabricate(:status, visibility: :direct)
  43. media_attachment = Fabricate(:media_attachment, status: status)
  44. get :show, params: { id: media_attachment.to_param }
  45. expect(response).to have_http_status(404)
  46. end
  47. end
  48. end
  49. end