Files
discourse/spec/serializers/basic_topic_serializer_spec.rb
Natalie Tay 5f00ae2ca9 DEV: Introduce plugin modifiers for post.cooked and topic.fancy_titles (#31261)
Related:
40fd82e2d1

This PR introduces three new plugin modifiers attached to 
- `basic_post_serializer.cooked`
- `basic_topic_serializer.fancy_title`
- `topic_view_serializer.fancy_title`

Implementation note: I had wanted to add them in the `Post` and `Topic`
models themselves, but they do not directly provide access to the
request's scope which is needed for the use case.
2025-02-14 00:19:50 +08:00

26 lines
784 B
Ruby

# frozen_string_literal: true
describe BasicTopicSerializer do
fab!(:topic) { Fabricate(:topic, title: "Hur dur this is a title") }
describe "#fancy_title" do
it "returns the fancy title" do
json = BasicTopicSerializer.new(topic).as_json
expect(json[:basic_topic][:fancy_title]).to eq(topic.title)
end
it "returns the fancy title with a modifier" do
plugin = Plugin::Instance.new
modifier = :topic_serializer_fancy_title
proc = Proc.new { "X" }
DiscoursePluginRegistry.register_modifier(plugin, modifier, &proc)
json = BasicTopicSerializer.new(topic).as_json
expect(json[:basic_topic][:fancy_title]).to eq("X")
ensure
DiscoursePluginRegistry.unregister_modifier(plugin, modifier, &proc)
end
end
end