Fix serialization when an account is missing (#38370)
This commit is contained in:
parent
c72ca33fac
commit
a3bdcc71e7
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user