mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-11 06:20:42 +00:00
Add id to collection serializers (#37157)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user