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
4 changes: 3 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ def spam?
end

def submit_spam
return unless approved && !is_deleted

Rails.env.production? && Akismetor.submit_spam(akismet_attributes)
end

Expand All @@ -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!
Expand Down
27 changes: 20 additions & 7 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -919,20 +919,33 @@ 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

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
Expand Down
Loading