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
2 changed files with 17 additions and 4 deletions

View File

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

View File

@@ -26,11 +26,14 @@ RSpec.describe REST::CollectionWithAccountsSerializer do
discoverable: false,
tag:)
end
before do
accounts[1..2].each do |account|
let(:collection_items) do
accounts[1..2].map do |account|
Fabricate(:collection_item, collection:, account:)
end
end
before do
collection_items
collection.reload
end
@@ -56,4 +59,14 @@ RSpec.describe REST::CollectionWithAccountsSerializer do
)
expect(subject['accounts'].size).to eq 3
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