From 4bad2f6afb6d49dd394d7e38109045be3880e7a8 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 20 Aug 2012 09:02:08 -0300 Subject: [PATCH] Add spam?/ham? methods to the comment class --- app/models/comment.rb | 8 ++++++++ test/unit/comment_test.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0939a20..33741d2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -188,4 +188,12 @@ class Comment < ActiveRecord::Base @rejected = true end + def spam? + !spam.nil? && spam + end + + def ham? + !spam.nil? && !spam + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 2847f8e..0352277 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -422,4 +422,19 @@ class CommentTest < ActiveSupport::TestCase assert_not_nil article.activity end + should 'be able to mark comments as spam/ham/unknown' do + c = Comment.new + c.spam = true + assert c.spam? + assert !c.ham? + + c.spam = false + assert c.ham? + assert !c.spam? + + c.spam = nil + assert !c.spam? + assert !c.ham? + end + end -- libgit2 0.21.2