diff --git a/app/models/comment.rb b/app/models/comment.rb index a46daf221c..c54cb75dec 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -510,6 +510,8 @@ def spam? end def submit_spam + return unless approved && !is_deleted + AkismetClient.submit_spam(akismet_attributes) end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index d45a34d175..0bdc937fd2 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -928,10 +928,16 @@ def queue_adapter_for_test expect(comment.approved).to be_falsey expect(comment.spam).to be_truthy end + + it "submits the comment to Akismet" do + expect(AkismetClient).to receive(:submit_spam) + + comment.mark_as_spam! + end end context "when the comment is already marked as spam" do - let(:comment) { create(:comment, approved: false, spam: false) } + let(:comment) { create_invalid(:comment, approved: false, spam: true) } it "flags the comment as spam" do comment.mark_as_spam! @@ -939,11 +945,27 @@ def queue_adapter_for_test expect(comment.approved).to be_falsey expect(comment.spam).to be_truthy end + + it "does not resubmit the comment to Akismet" do + expect(AkismetClient).not_to receive(:submit_spam) + + comment.mark_as_spam! + end + end + + context "when the comment is deleted" do + let(:comment) { create(:comment, approved: true, spam: false, is_deleted: true) } + + it "does not submit the comment to akismet" do + expect(AkismetClient).not_to receive(:submit_spam) + + comment.mark_as_spam! + end end end describe "#mark_as_ham!" do - let(:comment) { create(:comment, approved: false, spam: true) } + let(:comment) { create_invalid(:comment, approved: false, spam: true) } it "flags the comment as legitimate" do comment.mark_as_ham!