mastodon/spec/serializers/rest/collection_with_accounts_serializer_spec.rb
David Roetzel a3bdcc71e7
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Fix serialization when an account is missing (#38370)
2026-03-24 16:42:57 +00:00

73 lines
2.0 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe REST::CollectionWithAccountsSerializer do
subject do
serialized_record_json(collection, described_class, options: {
scope: current_user,
scope_name: :current_user,
})
end
let(:current_user) { nil }
let(:tag) { Fabricate(:tag, name: 'discovery') }
let(:accounts) { Fabricate.times(3, :account) }
let(:collection) do
Fabricate(:collection,
account: accounts.first,
id: 2342,
name: 'Exquisite follows',
description: 'Always worth a follow',
language: 'en',
local: true,
sensitive: true,
discoverable: false,
tag:)
end
let(:collection_items) do
accounts[1..2].map do |account|
Fabricate(:collection_item, collection:, account:)
end
end
before do
collection_items
collection.reload
end
it 'includes the relevant attributes' do
expect(subject)
.to include(
'accounts' => an_instance_of(Array),
'collection' => a_hash_including({
'account_id' => accounts.first.id.to_s,
'id' => '2342',
'name' => 'Exquisite follows',
'description' => 'Always worth a follow',
'language' => 'en',
'local' => true,
'sensitive' => true,
'discoverable' => false,
'tag' => a_hash_including('name' => 'discovery'),
'created_at' => match_api_datetime_format,
'updated_at' => match_api_datetime_format,
'item_count' => 2,
'items' => an_instance_of(Array),
})
)
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