mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00

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.
26 lines
784 B
Ruby
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
|