Commit 5521d9b4c262a089c443049486451490378de88a
1 parent
4bad2f6a
Exists in
master
and in
28 other branches
Named scope to select non-spam comments
ActionItem2306
Showing
2 changed files
with
10 additions
and
0 deletions
Show diff stats
app/models/comment.rb
| ... | ... | @@ -10,6 +10,8 @@ class Comment < ActiveRecord::Base |
| 10 | 10 | has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy |
| 11 | 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] | |
| 14 | + | |
| 13 | 15 | # unauthenticated authors: |
| 14 | 16 | validates_presence_of :name, :if => (lambda { |record| !record.email.blank? }) |
| 15 | 17 | validates_presence_of :email, :if => (lambda { |record| !record.name.blank? }) | ... | ... |
test/unit/comment_test.rb
| ... | ... | @@ -437,4 +437,12 @@ class CommentTest < ActiveSupport::TestCase |
| 437 | 437 | assert !c.ham? |
| 438 | 438 | end |
| 439 | 439 | |
| 440 | + should 'be able to select non-spam comments' do | |
| 441 | + c1 = fast_create(Comment) | |
| 442 | + c2 = fast_create(Comment, :spam => false) | |
| 443 | + c3 = fast_create(Comment, :spam => true) | |
| 444 | + | |
| 445 | + assert_equivalent [c1,c2], Comment.without_spam | |
| 446 | + end | |
| 447 | + | |
| 440 | 448 | end | ... | ... |