public
Fork of halorgium/mephisto
Description: A refactored Mephisto that has multiple spam detection engines.
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/francois/mephisto.git
Search Repo:
More specifications and code for integrating Comment with Defensio.
francois (author)
Sun Mar 02 20:16:26 -0800 2008
commit  248b11a9cc4d37901d6dba67765f831c105500d1
tree    f3351619b876057be9ae9547e14b108afc01a889
parent  38129499530bba80c81b07c22104b312e158c518
...
6
7
8
 
9
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
14
15
16
 
17
18
19
20
 
21
22
23
...
6
7
8
9
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
35
36
37
38
 
39
40
41
42
0
@@ -6,18 +6,37 @@ module Mephisto
0
       end
0
 
0
       def valid_key?
0
+ defensio.validate_key.success?
0
       end
0
 
0
       def ham?(request, comment)
0
- defensio
0
+ response = defensio.audit_comment(
0
+ # Required parameters
0
+ :user_ip => comment.author_ip,
0
+ :article_date => comment.article.published_at.strftime("%Y/%m/%d"),
0
+ :comment_author => comment.author,
0
+ :comment_type => "comment",
0
+
0
+ # Optional parameters
0
+ :comment_content => comment.body,
0
+ :comment_author_email => comment.author_email,
0
+ :comment_author_url => comment.author_url,
0
+ :permalink => "http://#{request.host_with_port}#{site.permalink_for(comment)}",
0
+ :referrer => comment.referrer,
0
+ :user_logged_in => false,
0
+ :trusted_user => false
0
+ )
0
+
0
+ comment.update_attribute(:spam_engine_data, {:signature => response.signature, :spaminess => response.spaminess.to_f})
0
+ !response.spam
0
       end
0
 
0
       def mark_as_ham(request, comment)
0
- defensio.mark_as_ham(comment)
0
+ defensio.report_false_positives(:signatures => comment.spam_engine_data[:signature])
0
       end
0
 
0
       def mark_as_spam(request, comment)
0
- defensio.mark_as_spam(comment)
0
+ defensio.report_false_negatives(:signatures => comment.spam_engine_data[:signature])
0
       end
0
 
0
       # The Defensio service supports statistics.
...
6
7
8
9
10
 
 
 
11
12
 
13
14
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
21
 
 
22
23
24
...
6
7
8
 
 
9
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
 
 
56
57
58
59
60
0
@@ -6,19 +6,55 @@ context "A properly configured Mephisto::SpamDetectionEngines::DefensioEngine" d
0
     @site.save(false)
0
     @engine = @site.spam_engine
0
 
0
- @request = stub("request", :host_with_port => "")
0
- @comment = Comment.new
0
+ @request = stub("request", :host_with_port => "my.host.com")
0
+ @article = Article.new(:published_at => 10.hours.ago)
0
+ @comment = Comment.new(:article => @article)
0
     @defensio = stub("defensio client")
0
- @site.stub!(:permalink_for).and_return("")
0
+ @site.stub!(:permalink_for).and_return("/2008/2/17/this-is-my-permalink")
0
   end
0
 
0
   specify "should be #valid?" do
0
     assert @engine.valid?
0
   end
0
+end
0
+
0
+context "A properly configured Mephisto::SpamDetectionEngines::DefensioEngine" do
0
+ before do
0
+ @site = Site.new(:spam_detection_engine => "Mephisto::SpamDetectionEngines::DefensioEngine")
0
+ @site.spam_engine_options = {:defensio_url => "http://my.blog.com/", :defensio_key => "akey"}
0
+ @site.save(false)
0
+ @engine = @site.spam_engine
0
+
0
+ @request = stub("request", :host_with_port => "my.host.com")
0
+ @article = Article.new(:published_at => 10.hours.ago)
0
+ @comment = Comment.new(:article => @article)
0
+ @defensio = stub("defensio client")
0
+ @site.stub!(:permalink_for).and_return("/2008/2/17/this-is-my-permalink")
0
+ Defensio::Client.stub!(:new).and_return(@defensio)
0
+ end
0
+
0
+ specify "should call #validate_key on #valid_key?" do
0
+ @defensio.should_receive(:validate_key).and_return(stub("defensio response", :success? => true))
0
+ assert @engine.valid_key?
0
+ end
0
+
0
+ specify "should call #report_false_positives on #mark_as_ham" do
0
+ @comment.should_receive(:spam_engine_data).and_return(:signature => "the-signature")
0
+ @defensio.should_receive(:report_false_positives).with(:signatures => ["the-signature"]).and_return(stub("response"))
0
+ @engine.mark_as_ham(@request, @comment)
0
+ end
0
+
0
+ specify "should call #report_false_negatives on #mark_as_spam" do
0
+ @comment.should_receive(:spam_engine_data).and_return(:signature => "a-signature")
0
+ @defensio.should_receive(:report_false_negatives).with(:signatures => ["a-signature"]).and_return(stub("response"))
0
+ @engine.mark_as_spam(@request, @comment)
0
+ end
0
+
0
+ specify "should call #audit_comment on #ham?" do
0
+ @defensio.should_receive(:audit_comment).with(any_args).and_return(stub("defensio response", :signature => "a signature", :spaminess => "0.43", :spam => false))
0
 
0
- specify "should instantiate a Defensio when calling #ham?" do
0
- Defensio::Client.should_receive(:new).and_return(@defensio)
0
- @engine.ham?(@request, @comment)
0
+ @comment.should_receive(:update_attribute).with(:spam_engine_data, {:spaminess => 0.43, :signature => "a signature"}).and_return(true)
0
+ assert @engine.ham?(@request, @comment)
0
   end
0
 end
0
 

Comments

    No one has commented yet.