Add id to collection serializers (#37157)

This commit is contained in:
David Roetzel
2025-12-08 12:40:17 +01:00
committed by GitHub
parent 55becaa1b5
commit cf23f0414f
3 changed files with 10 additions and 2 deletions

View File

@@ -1,11 +1,15 @@
# frozen_string_literal: true
class REST::BaseCollectionSerializer < ActiveModel::Serializer
attributes :uri, :name, :description, :local, :sensitive, :discoverable,
:item_count, :created_at, :updated_at
attributes :id, :uri, :name, :description, :local, :sensitive,
:discoverable, :item_count, :created_at, :updated_at
belongs_to :tag, serializer: REST::StatusSerializer::TagSerializer
def id
object.id.to_s
end
def item_count
object.respond_to?(:item_count) ? object.item_count : object.collection_items.count
end

View File

@@ -15,6 +15,7 @@ RSpec.describe REST::BaseCollectionSerializer do
let(:tag) { Fabricate(:tag, name: 'discovery') }
let(:collection) do
Fabricate(:collection,
id: 2342,
name: 'Exquisite follows',
description: 'Always worth a follow',
local: true,
@@ -26,6 +27,7 @@ RSpec.describe REST::BaseCollectionSerializer do
it 'includes the relevant attributes' do
expect(subject)
.to include(
'id' => '2342',
'name' => 'Exquisite follows',
'description' => 'Always worth a follow',
'local' => true,

View File

@@ -15,6 +15,7 @@ RSpec.describe REST::CollectionSerializer do
let(:tag) { Fabricate(:tag, name: 'discovery') }
let(:collection) do
Fabricate(:collection,
id: 2342,
name: 'Exquisite follows',
description: 'Always worth a follow',
local: true,
@@ -27,6 +28,7 @@ RSpec.describe REST::CollectionSerializer do
expect(subject)
.to include(
'account' => an_instance_of(Hash),
'id' => '2342',
'name' => 'Exquisite follows',
'description' => 'Always worth a follow',
'local' => true,