Fix tests

This commit is contained in:
Claire 2021-09-21 15:33:29 +02:00
parent 46db6a6340
commit 3ad653c4fd
2 changed files with 19 additions and 7 deletions

View File

@ -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)

View File

@ -62,14 +62,26 @@ 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 }
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
describe 'animated gif conversion' do
let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) }