Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 28 additions & 2 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -928,22 +928,48 @@ 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) { build(:comment, approved: false, spam: true) }

before { comment.save!(validate: false) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have create_invalid to make this a bit shorter. But that's a nitpick, so approving anyway, thank you!


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) { build(:comment, approved: false, spam: true) }

before { comment.save!(validate: false) }

it "flags the comment as legitimate" do
comment.mark_as_ham!
Expand Down
Loading