Skip to content

Commit a3bdcc7

Browse files
authored
Fix serialization when an account is missing (mastodon#38370)
1 parent c72ca33 commit a3bdcc7

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

app/serializers/rest/collection_with_accounts_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ def collection
1010
end
1111

1212
def accounts
13-
[object.account] + object.collection_items.map(&:account)
13+
[object.account] + object.collection_items.filter_map(&:account)
1414
end
1515
end

spec/serializers/rest/collection_with_accounts_serializer_spec.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
discoverable: false,
2727
tag:)
2828
end
29-
30-
before do
31-
accounts[1..2].each do |account|
29+
let(:collection_items) do
30+
accounts[1..2].map do |account|
3231
Fabricate(:collection_item, collection:, account:)
3332
end
33+
end
34+
35+
before do
36+
collection_items
3437
collection.reload
3538
end
3639

@@ -56,4 +59,14 @@
5659
)
5760
expect(subject['accounts'].size).to eq 3
5861
end
62+
63+
context 'when collection includes pending items without account' do
64+
let(:collection_items) do
65+
[Fabricate(:collection_item, collection:, account: nil, object_uri: 'https://example.com/actor/1', state: :pending)]
66+
end
67+
68+
it 'renders successfully' do
69+
expect(subject).to be_a Hash
70+
end
71+
end
5972
end

0 commit comments

Comments
 (0)