Commit 4bad2f6afb6d49dd394d7e38109045be3880e7a8
1 parent
9e4102e2
Exists in
master
and in
29 other branches
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
Showing
2 changed files
with
23 additions
and
0 deletions
Show diff stats
app/models/comment.rb
@@ -188,4 +188,12 @@ class Comment < ActiveRecord::Base | @@ -188,4 +188,12 @@ class Comment < ActiveRecord::Base | ||
188 | @rejected = true | 188 | @rejected = true |
189 | end | 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 | end | 199 | end |
test/unit/comment_test.rb
@@ -422,4 +422,19 @@ class CommentTest < ActiveSupport::TestCase | @@ -422,4 +422,19 @@ class CommentTest < ActiveSupport::TestCase | ||
422 | assert_not_nil article.activity | 422 | assert_not_nil article.activity |
423 | end | 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 | end | 440 | end |