diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb index a8c652582da..6462c85755d 100644 --- a/app/serializers/topic_list_serializer.rb +++ b/app/serializers/topic_list_serializer.rb @@ -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 diff --git a/spec/serializers/topic_list_serializer_spec.rb b/spec/serializers/topic_list_serializer_spec.rb index a914284e3a7..ed0ad38eccd 100644 --- a/spec/serializers/topic_list_serializer_spec.rb +++ b/spec/serializers/topic_list_serializer_spec.rb @@ -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