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
Initial integration of Mephisto + Defensio.
francois (author)
Sun Mar 02 19:11:25 -0800 2008
commit  f4d879e252a966cd5594bef6c372bda55b57d27b
tree    5da98ecde8d6d5a0f6696ba0412ebada7b909861
parent  1f7b806150e0affbb03e1826867eadf9a7e091d8
...
1
2
3
 
 
 
 
 
 
 
4
 
5
6
7
 
 
8
9
10
 
 
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
1
2
3
4
5
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
0
@@ -1,18 +1,39 @@
0
 module Mephisto
0
   module SpamDetectionEngines
0
     class DefensioEngine < Mephisto::SpamDetectionEngine::Base
0
+ def valid?
0
+ [:defensio_url, :defensio_key].all? {|key| options.has_key?(key)}
0
+ end
0
+
0
+ def valid_key?
0
+ end
0
+
0
       def ham?(request, comment)
0
+ defensio
0
       end
0
 
0
- def mark_as_ham(comment)
0
+ def mark_as_ham(request, comment)
0
+ defensio.mark_as_ham(comment)
0
       end
0
 
0
- def mark_as_spam(comment)
0
+ def mark_as_spam(request, comment)
0
+ defensio.mark_as_spam(comment)
0
       end
0
 
0
       # The Defensio service supports statistics.
0
       def statistics
0
       end
0
+
0
+ protected
0
+ def defensio
0
+ begin
0
+ @defensio ||= Defensio::Client.new(:owner_url => options[:defensio_url], :api_key => options[:defensio_key])
0
+ rescue Defensio::InvalidAPIKey
0
+ logger.warn { $! }
0
+ logger.warn { $!.backtrace.join("\n") }
0
+ raise Mephisto::SpamDetectionEngine::NotConfigured
0
+ end
0
+ end
0
     end
0
   end
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
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
61
62
63
64
65
66
67
68
69
70
71
0
@@ -0,0 +1,71 @@
0
+require File.dirname(__FILE__) + "/../../../test_helper"
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 => "")
0
+ @comment = Comment.new
0
+ @defensio = stub("defensio client")
0
+ @site.stub!(:permalink_for).and_return("")
0
+ end
0
+
0
+ specify "should be #valid?" do
0
+ assert @engine.valid?
0
+ end
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
+ end
0
+end
0
+
0
+context "A Mephisto::SpamDetectionEngines::DefensioEngine" do
0
+ before do
0
+ @site = Site.new(:spam_detection_engine => "Mephisto::SpamDetectionEngines::DefensioEngine")
0
+ @site.spam_engine_options = {}
0
+ @site.save(false)
0
+ @engine = @site.spam_engine
0
+ end
0
+
0
+ specify "should not be #valid? when the defensio key is missing from the options" do
0
+ @site.spam_engine_options.delete(:defensio_key)
0
+ @site.save(false)
0
+ assert !@site.spam_engine.valid?
0
+ end
0
+
0
+ specify "should not be #valid? when the defensio url is missing from the options" do
0
+ @site.spam_engine_options.delete(:defensio_url)
0
+ @site.save(false)
0
+ assert !@site.spam_engine.valid?
0
+ end
0
+end
0
+
0
+context "A Mephisto::SpamDetectionEngines::DefensioEngine instantiated from a Site with a missing :defensio_key" 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/"}
0
+ @site.save(false)
0
+ @engine = @site.spam_engine
0
+ end
0
+
0
+ specify "should raise a NotConfigured exception when calling #ham?" do
0
+ assert_raise Mephisto::SpamDetectionEngine::NotConfigured do
0
+ @site.spam_engine.ham?(nil, nil)
0
+ end
0
+ end
0
+
0
+ specify "should raise a NotConfigured exception when calling #mark_as_spam" do
0
+ assert_raise Mephisto::SpamDetectionEngine::NotConfigured do
0
+ @site.spam_engine.mark_as_spam(nil, nil)
0
+ end
0
+ end
0
+
0
+ specify "should raise a NotConfigured exception when calling #mark_as_ham" do
0
+ assert_raise Mephisto::SpamDetectionEngine::NotConfigured do
0
+ @site.spam_engine.mark_as_ham(nil, nil)
0
+ end
0
+ end
0
+end

Comments

    No one has commented yet.