mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-21 19:42:54 +08:00
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.
35 lines
1 KiB
Ruby
Vendored
35 lines
1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe BasicPostSerializer do
|
|
describe "#name" do
|
|
fab!(:user)
|
|
fab!(:post) { Fabricate(:post, user: user, cooked: "Hur dur I am a cooked raw") }
|
|
let(:serializer) { BasicPostSerializer.new(post, scope: Guardian.new, root: false) }
|
|
let(:json) { serializer.as_json }
|
|
|
|
it "returns the name it when `enable_names` is true" do
|
|
SiteSetting.enable_names = true
|
|
expect(json[:name]).to be_present
|
|
end
|
|
|
|
it "doesn't return the name it when `enable_names` is false" do
|
|
SiteSetting.enable_names = false
|
|
expect(json[:name]).to be_blank
|
|
end
|
|
|
|
describe "#cooked" do
|
|
it "returns the post's cooked" do
|
|
expect(json[:cooked]).to eq(post.cooked)
|
|
end
|
|
|
|
it "returns the localized cooked" do
|
|
SiteSetting.experimental_content_localization = true
|
|
Fabricate(:post_localization, post: post, cooked: "X", locale: "ja")
|
|
I18n.locale = "ja"
|
|
post.update!(locale: "en")
|
|
|
|
expect(json[:cooked]).to eq("X")
|
|
end
|
|
end
|
|
end
|
|
end
|