DEV: Set topic list filter name in serializer for children (#29291)

This commit is contained in:
Roman Rizzi 2024-10-18 17:24:47 -03:00 committed by GitHub
parent 1a66556f1a
commit 201c174b43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -14,6 +14,11 @@ class TopicListSerializer < ApplicationSerializer
has_many :tags, serializer: TagSerializer, embed: :objects
has_many :categories, serializer: CategoryBadgeSerializer, embed: :objects
def initialize(object, options = {})
super
options[:filter] = object.filter
end
def can_create_topic
scope.can_create?(Topic)
end

View File

@ -14,4 +14,13 @@ RSpec.describe TopicListSerializer do
expect(serialized[:primary_groups]).to eq([])
expect(serialized[:topic_list][:topics].first[:id]).to eq(topic.id)
end
it "adds filter name to the options hash so childrens can access it" do
filter = :hot
topic_list = TopicList.new(filter, user, [topic])
serializer = described_class.new(topic_list, scope: Guardian.new(user))
expect(serializer.options[:filter]).to eq(filter)
end
end