mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 02:12:09 +08:00
FIX: When displaying a reviewable, don't append the title to the content (#31851)
Follow up to e4401e587e98ac4020c2c4fd965e227146cf33d4. In the previous change, when serialising a Reviewable post, we were appending the title to the post content whilst checking for watched word matches. This append action was acting upon the object itself, rather than just a copy of the string, causing the UI to display the title appended twice to the content. Fortunately, since it was only happening in the serialiser, the incorrect data was never stored in the database, it was only happening when viewing the review queue.
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user