0
0
Fork 0

Limit attachments to MEDIA_ATTACHMENTS_LIMIT when returning posts through the API (#30932)

This commit is contained in:
Claire 2024-07-08 09:41:50 +02:00 committed by GitHub
parent fd3bfc0710
commit d41b43ed4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 7 deletions

View file

@ -247,6 +247,41 @@ RSpec.describe Status do
end
end
describe '#ordered_media_attachments' do
let(:status) { Fabricate(:status) }
let(:first_attachment) { Fabricate(:media_attachment) }
let(:second_attachment) { Fabricate(:media_attachment) }
let(:last_attachment) { Fabricate(:media_attachment) }
let(:extra_attachment) { Fabricate(:media_attachment) }
before do
stub_const('Status::MEDIA_ATTACHMENTS_LIMIT', 3)
# Add attachments out of order
status.media_attachments << second_attachment
status.media_attachments << last_attachment
status.media_attachments << extra_attachment
status.media_attachments << first_attachment
end
context 'when ordered_media_attachment_ids is not set' do
it 'returns up to MEDIA_ATTACHMENTS_LIMIT attachments' do
expect(status.ordered_media_attachments.size).to eq Status::MEDIA_ATTACHMENTS_LIMIT
end
end
context 'when ordered_media_attachment_ids is set' do
before do
status.update!(ordered_media_attachment_ids: [first_attachment.id, second_attachment.id, last_attachment.id, extra_attachment.id])
end
it 'returns up to MEDIA_ATTACHMENTS_LIMIT attachments in the expected order' do
expect(status.ordered_media_attachments).to eq [first_attachment, second_attachment, last_attachment]
end
end
end
describe '.mutes_map' do
subject { described_class.mutes_map([status.conversation.id], account) }