Permalink
Browse files

updated to not decrement ham count when moving from moderate to spam

  • Loading branch information...
1 parent ef33b76 commit 52b9e8b98dfb1cd51dd5213fd20016027d90a0ed RSL committed May 17, 2009
Showing with 40 additions and 6 deletions.
  1. +3 −0 README.rdoc
  2. +9 −1 lib/lucky_sneaks/acts_as_snook.rb
  3. +18 −5 test/acts_as_snook_interface_test.rb
  4. +10 −0 test/test_helper.rb
View
@@ -40,4 +40,7 @@ If you have provided a <tt>ham_comments_count</tt> attribute on your comment's p
Much love to Jonathan Snook, web developer extraordinaire. Most of the ideas/algorithms of ActsAsSnook [as well as the name, obviously] come from his blog post which you can find here[http://snook.ca/archives/other/effective_blog_comment_spam_blocker] The actual Ruby implementation I myself wrote.
+Thanks also to the following for their help and suggestions:
+Dana Jones
+
Copyright (c) 2008 Lucky Sneaks, released under the MIT license
@@ -267,6 +267,10 @@ def snook_spam_status_changed?
changes.has_key? self.class.fields_for_snooking[:spam_status_field].to_s
end
+ def snook_spam_status_changes
+ changes[self.class.fields_for_snooking[:spam_status_field].to_s]
+ end
+
def increment_ham_comments_count
if ham? && snook_entry
snook_entry.increment!(self.class.fields_for_snooking[:ham_comments_count_field])
@@ -275,7 +279,11 @@ def increment_ham_comments_count
def adjust_ham_comments_count
if snook_spam_status_changed?
- ham? ? increment_ham_comments_count : decrement_ham_comments_count
+ if ham?
+ increment_ham_comments_count
+ elsif snook_spam_status_changes == ["ham", "spam"]
+ decrement_ham_comments_count
+ end
end
end
@@ -29,11 +29,7 @@ def test_indicates_spam_status_of_ham
def test_indicates_spam_status_of_comments_needing_moderation
# This is a hard spot to hit!
- @comment = Comment.new(
- :author => "Mister Mxyzptlk",
- :url => "http://superman.de",
- :body => "I take viagra and cialis but I'm not selling it."
- )
+ @comment = Comment.new(MODERATE_COMMENT)
assert @comment.moderate?
end
@@ -141,6 +137,16 @@ def test_updating_spam_status_to_spam_decrements_ham_comment_count
@comment.destroy
end
+ def test_updating_moderate_spam_status_to_spam_does_not_decrement_ham_comments_count
+ @comment = Entry.find(:first).comments.create!(MODERATE_COMMENT)
+ @comment.save!
+ assert_no_difference("Entry.find(:first).ham_comments_count") do
+ @comment.spam_status = "spam"
+ @comment.save!
+ end
+ @comment.destroy
+ end
+
def test_destroying_ham_comment_decrements_ham_comment_count
@comment = Entry.find(:first).comments.create!(HAM_COMMENTS[0])
assert_difference "Entry.find(:first).ham_comments_count", -1 do
@@ -154,4 +160,11 @@ def test_destroying_spam_comment_does_not_decrement_ham_comment_count
@comment.destroy
end
end
+
+ def test_destroying_moderate_comment_does_not_decrement_ham_comment_count
+ @comment = Entry.find(:first).comments.create!(MODERATE_COMMENT)
+ assert_no_difference "Entry.find(:first).ham_comments_count" do
+ @comment.destroy
+ end
+ end
end
View
@@ -50,6 +50,10 @@ def bad_comment(options = {})
}.merge(options))
end
+ def moderate_comment(options = {})
+ Comment.new(MODERATE_COMMENT.merge(options))
+ end
+
def setup_prior_comments
good_comment.save
good_comment(:body => "Something different.").save
@@ -130,6 +134,12 @@ def setup_prior_comments
}
]
+ MODERATE_COMMENT = {
+ :author => "Mister Mxyzptlk",
+ :url => "http://superman.de",
+ :body => "I take viagra and cialis but I'm not selling it."
+ }
+
# From Active Support
def assert_difference(expressions, difference = 1, message = nil, &block)
expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send(:binding)) } }

0 comments on commit 52b9e8b

Please sign in to comment.