FIX: Return properly interpolated translations for flags

Currently, `FlagSerializer#short_description` properly provides
`base_path` to its translations, but `FlagSerializer#description` does
not. This breaks the link to guidelines when flagging a post, for
example.

This patch provides `base_path` for `FlagSerializer#description` too.
This commit is contained in:
Loïc Guitaut 2024-08-26 15:44:12 +02:00 committed by Loïc Guitaut
parent dd1abf91ef
commit cda596601b
2 changed files with 16 additions and 1 deletions

View File

@ -24,7 +24,11 @@ class FlagSerializer < ApplicationSerializer
end
def description
I18n.t("#{i18n_prefix}.description", default: object.description)
I18n.t(
"#{i18n_prefix}.description",
default: object.description.to_s,
base_path: Discourse.base_path,
)
end
def short_description

View File

@ -54,4 +54,15 @@ RSpec.describe FlagSerializer do
serialized = described_class.new(flag, used_flag_ids: []).as_json
expect(serialized[:flag][:applies_to]).to eq(%w[Post Topic Chat::Message])
end
describe "#description" do
let(:serializer) { described_class.new(flag, scope: Guardian.new, root: false) }
let(:flag) { Flag.find_by(name_key: :inappropriate) }
before { allow(Discourse).to receive(:base_path).and_return("discourse.org") }
it "returns properly interpolated translation" do
expect(serializer.description).to match(%r{discourse\.org/guidelines})
end
end
end