diff --git a/spec/controllers/media_controller_spec.rb b/spec/controllers/media_controller_spec.rb index 3c1d3303d..efd15b5b4 100644 --- a/spec/controllers/media_controller_spec.rb +++ b/spec/controllers/media_controller_spec.rb @@ -15,14 +15,14 @@ describe MediaController do context 'when the media attachment has a shortcode' do it 'redirects to the file url when attached to a status' do status = Fabricate(:status) - media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'foo') + media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'OI6IgDzG-nYTqvDQ994') get :show, params: { id: media_attachment.to_param } expect(response).to redirect_to(media_attachment.file.url(:original)) end it 'responds with missing when there is not an attached status' do - media_attachment = Fabricate(:media_attachment, status: nil, shortcode: 'foo') + media_attachment = Fabricate(:media_attachment, status: nil, shortcode: 'OI6IgDzG-nYTqvDQ994') get :show, params: { id: media_attachment.to_param } expect(response).to have_http_status(404) @@ -30,7 +30,7 @@ describe MediaController do it 'raises when not permitted to view' do status = Fabricate(:status, visibility: :direct) - media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'foo') + media_attachment = Fabricate(:media_attachment, status: status, shortcode: 'OI6IgDzG-nYTqvDQ994') get :show, params: { id: media_attachment.to_param } expect(response).to have_http_status(404) diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index 456bc4216..30e42a9b4 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -62,11 +62,23 @@ RSpec.describe MediaAttachment, type: :model do end describe '#to_param' do - let(:media_attachment) { Fabricate(:media_attachment) } - let(:shortcode) { media_attachment.shortcode } + let(:media_attachment) { Fabricate(:media_attachment, shortcode: shortcode) } + let(:shortcode) { nil } - it 'returns shortcode' do - expect(media_attachment.to_param).to eq shortcode + context 'when media attachment has a shortcode' do + let(:shortcode) { 'foo' } + + it 'returns shortcode' do + expect(media_attachment.to_param).to eq shortcode + end + end + + context 'when media attachment does not have a shortcode' do + let(:shortcode) { nil } + + it 'returns string representation of id' do + expect(media_attachment.to_param).to eq media_attachment.id.to_s + end end end