Fix serialization when an account is missing (#38370)

This commit is contained in:
David Roetzel 2026-03-24 17:42:57 +01:00 committed by GitHub
parent c72ca33fac
commit a3bdcc71e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -10,6 +10,6 @@ class REST::CollectionWithAccountsSerializer < ActiveModel::Serializer
end end
def accounts def accounts
[object.account] + object.collection_items.map(&:account) [object.account] + object.collection_items.filter_map(&:account)
end end
end end

View File

@ -26,11 +26,14 @@ RSpec.describe REST::CollectionWithAccountsSerializer do
discoverable: false, discoverable: false,
tag:) tag:)
end end
let(:collection_items) do
before do accounts[1..2].map do |account|
accounts[1..2].each do |account|
Fabricate(:collection_item, collection:, account:) Fabricate(:collection_item, collection:, account:)
end end
end
before do
collection_items
collection.reload collection.reload
end end
@ -56,4 +59,14 @@ RSpec.describe REST::CollectionWithAccountsSerializer do
) )
expect(subject['accounts'].size).to eq 3 expect(subject['accounts'].size).to eq 3
end end
context 'when collection includes pending items without account' do
let(:collection_items) do
[Fabricate(:collection_item, collection:, account: nil, object_uri: 'https://example.com/actor/1', state: :pending)]
end
it 'renders successfully' do
expect(subject).to be_a Hash
end
end
end end