From 5521d9b4c262a089c443049486451490378de88a Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 20 Aug 2012 09:18:29 -0300 Subject: [PATCH] Named scope to select non-spam comments --- app/models/comment.rb | 2 ++ test/unit/comment_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 33741d2..db383cb 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,6 +10,8 @@ class Comment < ActiveRecord::Base has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' + named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] + # unauthenticated authors: validates_presence_of :name, :if => (lambda { |record| !record.email.blank? }) validates_presence_of :email, :if => (lambda { |record| !record.name.blank? }) diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 0352277..274d7cd 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -437,4 +437,12 @@ class CommentTest < ActiveSupport::TestCase assert !c.ham? end + should 'be able to select non-spam comments' do + c1 = fast_create(Comment) + c2 = fast_create(Comment, :spam => false) + c3 = fast_create(Comment, :spam => true) + + assert_equivalent [c1,c2], Comment.without_spam + end + end -- libgit2 0.21.2