mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 07:49:29 +00:00
Add id to collection serializers (#37157)
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class REST::BaseCollectionSerializer < ActiveModel::Serializer
|
class REST::BaseCollectionSerializer < ActiveModel::Serializer
|
||||||
attributes :uri, :name, :description, :local, :sensitive, :discoverable,
|
attributes :id, :uri, :name, :description, :local, :sensitive,
|
||||||
:item_count, :created_at, :updated_at
|
:discoverable, :item_count, :created_at, :updated_at
|
||||||
|
|
||||||
belongs_to :tag, serializer: REST::StatusSerializer::TagSerializer
|
belongs_to :tag, serializer: REST::StatusSerializer::TagSerializer
|
||||||
|
|
||||||
|
def id
|
||||||
|
object.id.to_s
|
||||||
|
end
|
||||||
|
|
||||||
def item_count
|
def item_count
|
||||||
object.respond_to?(:item_count) ? object.item_count : object.collection_items.count
|
object.respond_to?(:item_count) ? object.item_count : object.collection_items.count
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ RSpec.describe REST::BaseCollectionSerializer do
|
|||||||
let(:tag) { Fabricate(:tag, name: 'discovery') }
|
let(:tag) { Fabricate(:tag, name: 'discovery') }
|
||||||
let(:collection) do
|
let(:collection) do
|
||||||
Fabricate(:collection,
|
Fabricate(:collection,
|
||||||
|
id: 2342,
|
||||||
name: 'Exquisite follows',
|
name: 'Exquisite follows',
|
||||||
description: 'Always worth a follow',
|
description: 'Always worth a follow',
|
||||||
local: true,
|
local: true,
|
||||||
@@ -26,6 +27,7 @@ RSpec.describe REST::BaseCollectionSerializer do
|
|||||||
it 'includes the relevant attributes' do
|
it 'includes the relevant attributes' do
|
||||||
expect(subject)
|
expect(subject)
|
||||||
.to include(
|
.to include(
|
||||||
|
'id' => '2342',
|
||||||
'name' => 'Exquisite follows',
|
'name' => 'Exquisite follows',
|
||||||
'description' => 'Always worth a follow',
|
'description' => 'Always worth a follow',
|
||||||
'local' => true,
|
'local' => true,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ RSpec.describe REST::CollectionSerializer do
|
|||||||
let(:tag) { Fabricate(:tag, name: 'discovery') }
|
let(:tag) { Fabricate(:tag, name: 'discovery') }
|
||||||
let(:collection) do
|
let(:collection) do
|
||||||
Fabricate(:collection,
|
Fabricate(:collection,
|
||||||
|
id: 2342,
|
||||||
name: 'Exquisite follows',
|
name: 'Exquisite follows',
|
||||||
description: 'Always worth a follow',
|
description: 'Always worth a follow',
|
||||||
local: true,
|
local: true,
|
||||||
@@ -27,6 +28,7 @@ RSpec.describe REST::CollectionSerializer do
|
|||||||
expect(subject)
|
expect(subject)
|
||||||
.to include(
|
.to include(
|
||||||
'account' => an_instance_of(Hash),
|
'account' => an_instance_of(Hash),
|
||||||
|
'id' => '2342',
|
||||||
'name' => 'Exquisite follows',
|
'name' => 'Exquisite follows',
|
||||||
'description' => 'Always worth a follow',
|
'description' => 'Always worth a follow',
|
||||||
'local' => true,
|
'local' => true,
|
||||||
|
|||||||
Reference in New Issue
Block a user