1
0

media_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Media' do
  4. describe 'GET /media/:id' do
  5. context 'when the media attachment does not exist' do
  6. it 'responds with not found' do
  7. get '/media/missing'
  8. expect(response)
  9. .to have_http_status(404)
  10. end
  11. end
  12. context 'when the media attachment has a shortcode' do
  13. let(:media_attachment) { Fabricate :media_attachment, status: status, shortcode: 'OI6IgDzG-nYTqvDQ994' }
  14. context 'when attached to a status' do
  15. let(:status) { Fabricate :status }
  16. it 'redirects to file url' do
  17. get medium_path(id: media_attachment.shortcode)
  18. expect(response)
  19. .to redirect_to(media_attachment.file.url(:original))
  20. end
  21. end
  22. context 'when not attached to a status' do
  23. let(:status) { nil }
  24. it 'responds with not found' do
  25. get medium_path(id: media_attachment.shortcode)
  26. expect(response)
  27. .to have_http_status(404)
  28. end
  29. end
  30. context 'when attached to non-public status' do
  31. let(:status) { Fabricate :status, visibility: :direct }
  32. it 'responds with not found' do
  33. get medium_path(id: media_attachment.shortcode)
  34. expect(response)
  35. .to have_http_status(404)
  36. end
  37. end
  38. end
  39. context 'when the media attachment does not have a shortcode' do
  40. let(:media_attachment) { Fabricate :media_attachment, status: status, shortcode: nil }
  41. context 'when attached to a status' do
  42. let(:status) { Fabricate :status }
  43. it 'redirects to file url' do
  44. get medium_path(id: media_attachment.id)
  45. expect(response)
  46. .to redirect_to(media_attachment.file.url(:original))
  47. end
  48. end
  49. context 'when not attached to a status' do
  50. let(:status) { nil }
  51. it 'responds with not found' do
  52. get medium_path(id: media_attachment.id)
  53. expect(response)
  54. .to have_http_status(404)
  55. end
  56. end
  57. context 'when attached to non-public status' do
  58. let(:status) { Fabricate :status, visibility: :direct }
  59. it 'responds with not found' do
  60. get medium_path(id: media_attachment.id)
  61. expect(response)
  62. .to have_http_status(404)
  63. end
  64. end
  65. end
  66. end
  67. end