Commit 4bad2f6afb6d49dd394d7e38109045be3880e7a8

Authored by Antonio Terceiro
1 parent 9e4102e2

Add spam?/ham? methods to the comment class

While the knowledge about spam and ham is included in the Noosfero core,
actually checking comments for spam is delegated to plugins. This way
we can have multiple ways of checking for spam.

ActionItem2306
app/models/comment.rb
... ... @@ -188,4 +188,12 @@ class Comment < ActiveRecord::Base
188 188 @rejected = true
189 189 end
190 190  
  191 + def spam?
  192 + !spam.nil? && spam
  193 + end
  194 +
  195 + def ham?
  196 + !spam.nil? && !spam
  197 + end
  198 +
191 199 end
... ...
test/unit/comment_test.rb
... ... @@ -422,4 +422,19 @@ class CommentTest < ActiveSupport::TestCase
422 422 assert_not_nil article.activity
423 423 end
424 424  
  425 + should 'be able to mark comments as spam/ham/unknown' do
  426 + c = Comment.new
  427 + c.spam = true
  428 + assert c.spam?
  429 + assert !c.ham?
  430 +
  431 + c.spam = false
  432 + assert c.ham?
  433 + assert !c.spam?
  434 +
  435 + c.spam = nil
  436 + assert !c.spam?
  437 + assert !c.ham?
  438 + end
  439 +
425 440 end
... ...