Permalink
Browse files

Use "splam?" instead of "spam?" so we don't overwrite other spam libs

  • Loading branch information...
1 parent 4a28b30 commit 5a8197b572e28777e5c746578375125ccbf0016e @courtenay committed Dec 27, 2008
Showing with 10 additions and 9 deletions.
  1. +1 −1 README
  2. +4 −3 lib/splam.rb
  3. +5 −5 test/splam_test.rb
View
@@ -32,7 +32,7 @@ Recommended serving directions:
end
comment = Comment.new :body => "This is spam!!!1"
- comment.spam? # => false
+ comment.splam? # => false
comment.splam_score # => 2
comment.splam_reasons # => []
View
@@ -15,7 +15,7 @@ def self.included(base)
module ClassMethods
def splam; @splam; end
- def splammable(fieldname, threshold=100)
+ def splammable(fieldname, threshold=100, conditions=nil)
run_rules = []
# todo: run only certain rules
# e.g. splammable :body, 100, [ :chinese, :html ]
@@ -26,12 +26,13 @@ def splammable(fieldname, threshold=100)
@splam[:rules] = Splam::Rule.subclasses
@splam[:threshold] = threshold
@splam[:fieldname] = fieldname
+ @splam[:conditions] = conditions
end
end
def splam_score; @splam_score; end
def splam_reasons; @splam_reasons; end
- def spam?
+ def splam?
@splam_score = 0
@splam_reasons = []
splam = self.class.splam || raise("Splam is not initialized")
@@ -46,6 +47,6 @@ def spam?
end
def validates_as_spam
- errors.add(@splam[:fieldname], "looks like spam.") if spam?
+ errors.add(@splam[:fieldname], "looks like spam.") if splam?
end
end
View
@@ -21,7 +21,7 @@ class SplamTest < Test::Unit::TestCase
def test_runs_plugins
f = Foo.new
- assert ! f.spam?
+ assert ! f.splam?
assert_equal 10, f.splam_score
end
@@ -37,24 +37,24 @@ def test_scores_spam_really_high
else
Foo.splam[:threshold] = 99
end
- comment.spam? # todo: assert
+ spam = comment.splam?
score = comment.splam_score
#$stderr.puts "#{f} score: #{score}"
#$stderr.puts "====================="
- assert comment.spam?, "Comment #{f} was not spam, score was #{score} but threshold was #{Foo.splam[:threshold]}\nReasons were #{comment.splam_reasons.inspect}"
+ assert spam, "Comment #{f} was not spam, score was #{score} but threshold was #{Foo.splam[:threshold]}\nReasons were #{comment.splam_reasons.inspect}"
end
end
def test_scores_ham_low
comment = Foo.new
Dir.glob(File.join(File.dirname(__FILE__), "fixtures", "comment", "ham", "*.txt")).each do |f|
comment.body = File.open(f).read
- comment.spam?
+ spam = comment.splam?
score = comment.splam_score
#$stderr.puts "#{f} score: #{score}"
#$stderr.puts "====================="
- assert !comment.spam?, "File #{f} should be marked ham, but was marked with score #{score}\nReasons were #{comment.splam_reasons}\n\n#{comment.body}"
+ assert !spam, "File #{f} should be marked ham, but was marked with score #{score}\nReasons were #{comment.splam_reasons}\n\n#{comment.body}"
end
end
end

0 comments on commit 5a8197b

Please sign in to comment.