Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ def spam?
end

def submit_spam
return unless approved && !is_deleted

AkismetClient.submit_spam(akismet_attributes)
end

Expand Down
26 changes: 24 additions & 2 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -928,22 +928,44 @@ 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!
comment.reload
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!
Expand Down
Loading