mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
DEV: Set topic list filter name in serializer for children (#29291)
This commit is contained in:
@ -14,6 +14,11 @@ class TopicListSerializer < ApplicationSerializer
|
|||||||
has_many :tags, serializer: TagSerializer, embed: :objects
|
has_many :tags, serializer: TagSerializer, embed: :objects
|
||||||
has_many :categories, serializer: CategoryBadgeSerializer, embed: :objects
|
has_many :categories, serializer: CategoryBadgeSerializer, embed: :objects
|
||||||
|
|
||||||
|
def initialize(object, options = {})
|
||||||
|
super
|
||||||
|
options[:filter] = object.filter
|
||||||
|
end
|
||||||
|
|
||||||
def can_create_topic
|
def can_create_topic
|
||||||
scope.can_create?(Topic)
|
scope.can_create?(Topic)
|
||||||
end
|
end
|
||||||
|
@ -14,4 +14,13 @@ RSpec.describe TopicListSerializer do
|
|||||||
expect(serialized[:primary_groups]).to eq([])
|
expect(serialized[:primary_groups]).to eq([])
|
||||||
expect(serialized[:topic_list][:topics].first[:id]).to eq(topic.id)
|
expect(serialized[:topic_list][:topics].first[:id]).to eq(topic.id)
|
||||||
end
|
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
|
end
|
||||||
|
Reference in New Issue
Block a user