From c0ee547d13eb7a791cbb0fd71d90e8d4bdcdfd02 Mon Sep 17 00:00:00 2001 From: Julian Saxl Date: Sat, 4 Apr 2026 10:08:30 -0600 Subject: [PATCH 1/2] AO3-7320 Check whether comment is already marked as spam or deleted before marking as spam --- app/models/comment.rb | 4 +++- spec/models/comment_spec.rb | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 3da6c01f61c..04ebb18a638 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -514,6 +514,8 @@ def spam? end def submit_spam + return unless approved && !is_deleted + Rails.env.production? && Akismetor.submit_spam(akismet_attributes) end @@ -522,9 +524,9 @@ def submit_ham end def mark_as_spam! + submit_spam update_attribute(:approved, false) update_attribute(:spam, true) - submit_spam end def mark_as_ham! diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 699dfe792c2..43a746081ea 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -919,13 +919,26 @@ def queue_adapter_for_test end describe "#mark_as_spam!" do - let(:comment) { create(:comment, approved: true, spam: false) } + context "when the comment is not marked as spam" do + let(:comment) { create(:comment, approved: true, spam: false) } - it "flags the comment as spam." do - comment.mark_as_spam! - comment.reload - expect(comment.approved).to be_falsey - expect(comment.spam).to be_truthy + it "flags the comment as spam." do + comment.mark_as_spam! + comment.reload + expect(comment.approved).to be_falsey + expect(comment.spam).to be_truthy + end + end + + context "when the comment is already marked as spam" do + let(:comment) { create(:comment, approved: false, spam: false) } + + it "flags the comment as spam." do + comment.mark_as_spam! + comment.reload + expect(comment.approved).to be_falsey + expect(comment.spam).to be_truthy + end end end From 33f845b8dd772a65ba334f59dba206a7e2d9072b Mon Sep 17 00:00:00 2001 From: Julian Saxl Date: Mon, 6 Apr 2026 11:17:53 -0600 Subject: [PATCH 2/2] AO3-7320 Adapt test context message to match other test cases --- spec/models/comment_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 43a746081ea..d45a34d175c 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -922,7 +922,7 @@ def queue_adapter_for_test context "when the comment is not marked as spam" do let(:comment) { create(:comment, approved: true, spam: false) } - it "flags the comment as spam." do + it "flags the comment as spam" do comment.mark_as_spam! comment.reload expect(comment.approved).to be_falsey @@ -933,7 +933,7 @@ def queue_adapter_for_test context "when the comment is already marked as spam" do let(:comment) { create(:comment, approved: false, spam: false) } - it "flags the comment as spam." do + it "flags the comment as spam" do comment.mark_as_spam! comment.reload expect(comment.approved).to be_falsey @@ -945,7 +945,7 @@ def queue_adapter_for_test describe "#mark_as_ham!" do let(:comment) { create(:comment, approved: false, spam: true) } - it "flags the comment as legitimate." do + it "flags the comment as legitimate" do comment.mark_as_ham! comment.reload expect(comment.approved).to be_truthy