From 636d05fc20a7cbbc81a7318d21c50a5bf89d6eb7 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Wed, 14 Aug 2024 15:53:59 -0300 Subject: [PATCH] FEATURE: Allow completely custom score reasons. (#28348) After this change, a reason won't exclusively be a translation key anymore, but now, it can display a custom reason as well. --- app/serializers/reviewable_score_serializer.rb | 4 ++-- spec/serializers/reviewable_score_serializer_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/serializers/reviewable_score_serializer.rb b/app/serializers/reviewable_score_serializer.rb index 01f9be909d4..32e084e4328 100644 --- a/app/serializers/reviewable_score_serializer.rb +++ b/app/serializers/reviewable_score_serializer.rb @@ -42,9 +42,9 @@ class ReviewableScoreSerializer < ApplicationSerializer if link_text link = build_link_for(object.reason, link_text) - text = I18n.t("reviewables.reasons.#{object.reason}", link: link, default: nil) + text = I18n.t("reviewables.reasons.#{object.reason}", link: link, default: object.reason) else - text = I18n.t("reviewables.reasons.#{object.reason}", default: nil) + text = I18n.t("reviewables.reasons.#{object.reason}", default: object.reason) end text diff --git a/spec/serializers/reviewable_score_serializer_spec.rb b/spec/serializers/reviewable_score_serializer_spec.rb index d23756a0381..cd603e7de02 100644 --- a/spec/serializers/reviewable_score_serializer_spec.rb +++ b/spec/serializers/reviewable_score_serializer_spec.rb @@ -54,6 +54,15 @@ RSpec.describe ReviewableScoreSerializer do end end end + + context "with custom reasons" do + it "serializes it without doing any translation" do + custom = "completely custom flag reason" + serialized = serialized_score(custom) + + expect(serialized.reason).to eq(custom) + end + end end describe "#setting_name_for_reason" do