From cda596601bf9b1a6a8dd48d7267acd55e8fb7df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Mon, 26 Aug 2024 15:44:12 +0200 Subject: [PATCH] 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. --- app/serializers/flag_serializer.rb | 6 +++++- spec/serializers/flag_serializer_spec.rb | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/serializers/flag_serializer.rb b/app/serializers/flag_serializer.rb index 8901710217e..b7e4e927e3e 100644 --- a/app/serializers/flag_serializer.rb +++ b/app/serializers/flag_serializer.rb @@ -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 diff --git a/spec/serializers/flag_serializer_spec.rb b/spec/serializers/flag_serializer_spec.rb index ad949180a87..507e3e8c078 100644 --- a/spec/serializers/flag_serializer_spec.rb +++ b/spec/serializers/flag_serializer_spec.rb @@ -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