Skip to content

A platform for community discussion. Free, open, simple.

FIX: When displaying a reviewable, don't append the title to the content (#31851)

Gary Pendergast9d14492f224d
diff --git a/app/serializers/reviewable_score_serializer.rb b/app/serializers/reviewable_score_serializer.rb
index 989456eb2c8..1fe7b888e0e 100644
--- a/app/serializers/reviewable_score_serializer.rb
+++ b/app/serializers/reviewable_score_serializer.rb
@@ -78,10 +78,10 @@ class ReviewableScoreSerializer < ApplicationSerializer
if object.context.nil?
# If the words weren't recorded, try to guess them based on current settings.
if object.reviewable.respond_to?(:post)
- s = object.reviewable.post.raw
+ s = object.reviewable.post.raw.clone
s << " #{object.reviewable.post.topic.title}" if object.reviewable.post.post_number == 1
elsif object.reviewable.respond_to?(:payload)
- s = object.reviewable.payload["raw"]
+ s = object.reviewable.payload["raw"].clone
s << " #{object.reviewable.payload["title"]}" if object.reviewable.payload.key?("title")
end
diff --git a/spec/serializers/reviewable_score_serializer_spec.rb b/spec/serializers/reviewable_score_serializer_spec.rb
index 1f6bbc9fe08..3248bc251f5 100644
--- a/spec/serializers/reviewable_score_serializer_spec.rb
+++ b/spec/serializers/reviewable_score_serializer_spec.rb
@@ -69,8 +69,8 @@ RSpec.describe ReviewableScoreSerializer do
"<a href=\"#{Discourse.base_url}/admin/customize/watched_words\">#{I18n.t("reviewables.reasons.links.watched_word")}</a>"
end
it "tries to guess the watched words if they weren't recorded at the time of flagging" do
- reviewable.target =
- Fabricate(:post, raw: "I'm a post with some bad words like 'bad' and 'words'.")
+ raw = "I'm a post with some bad words like 'bad' and 'words'."
+ reviewable.target = Fabricate(:post, raw:)
score = serialized_score("watched_word")
@@ -78,10 +78,13 @@ RSpec.describe ReviewableScoreSerializer do
Fabricate(:watched_word, action: WatchedWord.actions[:flag], word: "words")
expect(score.reason).to include("bad, words")
+
+ expect(reviewable.target.raw).to eq(raw)
end
it "handles guessing the watched words when the post hasn't been created yet" do
queued_reviewable = Fabricate(:reviewable_queued_post_topic)
+ raw = queued_reviewable.payload["raw"].clone
reviewable_score =
ReviewableScore.new(reviewable: queued_reviewable, reason: "watched_word")
@@ -90,6 +93,7 @@ RSpec.describe ReviewableScoreSerializer do
result = described_class.new(reviewable_score, scope: Guardian.new(admin), root: nil)
expect(result.reason).to include("contents, title")
+ expect(queued_reviewable.payload["raw"]).to eq(raw)
end
it "uses the no-context message if the post has no watched words" do