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.

37 lines
1.2 KiB

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