Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed snook calculation to only on create

  • Loading branch information...
commit f2aa711cf89c068ade1442076e085703234d2a26 2 parents be95ec9 + 20feb5b
rsl authored
View
15 lib/lucky_sneaks/acts_as_snook.rb
@@ -65,23 +65,31 @@ def moderate(options = {})
# Returns true if marked as spam, false otherwise
def spam?
- calculate_snook_score unless snook_credits
+ calculate_snook_score unless already_calculated_snook
snook_spam_status == "spam"
end
# Returns true if marked as ham (safe to display), false if spam
def ham?
- calculate_snook_score unless snook_credits
+ calculate_snook_score unless already_calculated_snook
snook_spam_status == "ham"
end
# Returns true if marked as spam, false otherwise
def moderate?
- calculate_snook_score unless snook_credits
+ calculate_snook_score unless already_calculated_snook
snook_spam_status == "moderate"
end
+ def ham!
+ update_attribute :spam_status, "ham"
+ end
+
private
+ def already_calculated_snook
+ self.send(self.class.fields_for_snooking[:spam_status_field]) || snook_credits
+ end
+
def calculate_snook_for_body_links
link_count = snook_body.scan(/http:/).size
if link_count > 2
@@ -175,6 +183,7 @@ def calculate_snook_score
"spam"
end
self.send("#{self.class.fields_for_snooking[:spam_status_field]}=", status)
+ snook_credits >= -10
end
def snook_author
View
22 test/acts_as_snook_interface_test.rb
@@ -3,10 +3,10 @@
class ActsAsSnookInterfaceTest < Test::Unit::TestCase
def test_marks_spam_as_spam
SPAM_COMMENTS.each do |comment_attributes|
- @comment = Comment.create(comment_attributes)
+ @comment = Comment.new(comment_attributes)
+ @comment.valid?
assert_equal "spam", @comment.spam_status
end
- Comment.destroy_all
end
def test_marks_ham_as_ham
@@ -69,15 +69,27 @@ def test_cannot_mass_assign_spam_status
assert_not_equal "ham", @comment.spam_status
end
+ def test_does_not_save_if_snook_credits_lower_than_negative_ten
+ @comment = Comment.new(SPAM_COMMENTS.first)
+ @comment.valid?
+ assert @comment.snook_credits < -10
+ assert !@comment.save
+ end
+
+ def test_ham_exclamation_point_updates_spam_status_to_ham
+ @comment = Comment.create!(SPAM_COMMENTS[2])
+ assert @comment.spam?
+ @comment.ham!
+ assert @comment.ham?
+ @comment.destroy
+ end
+
def test_resaving_comment_with_changed_status_does_not_mark_as_spam
@comment = bad_comment
@comment.save!
-
@comment.update_attribute(:spam_status, "ham")
assert @comment.ham?
@comment.save
- assert @comment.ham?
-
@comment.destroy
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.