Commit e5f686404a797b5f43f690253b6c11e259799e47
1 parent
dcaa721a
Exists in
master
and in
29 other branches
Selecting spammy comments
ActionItem2306
Showing
2 changed files
with
9 additions
and
0 deletions
Show diff stats
app/models/comment.rb
@@ -11,6 +11,7 @@ class Comment < ActiveRecord::Base | @@ -11,6 +11,7 @@ class Comment < ActiveRecord::Base | ||
11 | belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' | 11 | belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' |
12 | 12 | ||
13 | named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] | 13 | named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] |
14 | + named_scope :spam, :conditions => ['spam = ?', true] | ||
14 | 15 | ||
15 | # unauthenticated authors: | 16 | # unauthenticated authors: |
16 | validates_presence_of :name, :if => (lambda { |record| !record.email.blank? }) | 17 | validates_presence_of :name, :if => (lambda { |record| !record.email.blank? }) |
test/unit/comment_test.rb
@@ -452,4 +452,12 @@ class CommentTest < ActiveSupport::TestCase | @@ -452,4 +452,12 @@ class CommentTest < ActiveSupport::TestCase | ||
452 | assert c1.spam? | 452 | assert c1.spam? |
453 | end | 453 | end |
454 | 454 | ||
455 | + should 'be able to select spammy comments' do | ||
456 | + c1 = fast_create(Comment) | ||
457 | + c2 = fast_create(Comment, :spam => false) | ||
458 | + c3 = fast_create(Comment, :spam => true) | ||
459 | + | ||
460 | + assert_equivalent [c3], Comment.spam | ||
461 | + end | ||
462 | + | ||
455 | end | 463 | end |