mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 16:02:46 +08:00
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:
parent
dd1abf91ef
commit
cda596601b
|
@ -24,7 +24,11 @@ class FlagSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
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
|
end
|
||||||
|
|
||||||
def short_description
|
def short_description
|
||||||
|
|
|
@ -54,4 +54,15 @@ RSpec.describe FlagSerializer do
|
||||||
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
||||||
expect(serialized[:flag][:applies_to]).to eq(%w[Post Topic Chat::Message])
|
expect(serialized[:flag][:applies_to]).to eq(%w[Post Topic Chat::Message])
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user