discourse/spec/serializers/basic_topic_serializer_spec.rb
Natalie Tay 51ebe7064c
FEATURE: Show localized posts and topics based on user's locale (#32618)
Related:
- https://github.com/discourse/discourse-translator/pull/205
- https://github.com/discourse/discourse-translator/pull/274
- https://github.com/discourse/discourse-translator/pull/294

With this PR, we will start showing localized posts (if available) based
on the user's locale.

This work had been done in discourse-translator, but is now moving to
core.
2025-05-15 19:11:06 +08:00

24 lines
708 B
Ruby
Vendored

# 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
SiteSetting.experimental_content_localization = true
Fabricate(:topic_localization, topic:, fancy_title: "X", locale: "ja")
I18n.locale = "ja"
topic.update!(locale: "en")
json = BasicTopicSerializer.new(topic).as_json
expect(json[:basic_topic][:fancy_title]).to eq("X")
end
end
end