mollom 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mollom.rb +5 -3
- data/test/mollom_test.rb +26 -14
- metadata +3 -3
data/lib/mollom.rb
CHANGED
@@ -10,7 +10,7 @@ class Mollom
|
|
10
10
|
module Errors
|
11
11
|
Standard = 1000
|
12
12
|
Refresh = 1100
|
13
|
-
|
13
|
+
TooBusy = 1200
|
14
14
|
end
|
15
15
|
|
16
16
|
attr_accessor :private_key, :public_key
|
@@ -85,6 +85,8 @@ class Mollom
|
|
85
85
|
# Standard check to see if your public/private keypair are recognized. Takes no options
|
86
86
|
def key_ok?
|
87
87
|
return send_command('mollom.verifyKey')
|
88
|
+
rescue XMLRPC::FaultException
|
89
|
+
return false
|
88
90
|
end
|
89
91
|
|
90
92
|
# Gets some statistics from Mollom about your site.
|
@@ -140,10 +142,10 @@ class Mollom
|
|
140
142
|
case error.faultCode
|
141
143
|
when Errors::Standard
|
142
144
|
raise Error.new(error.faultString)
|
143
|
-
when Errors::Refresh
|
145
|
+
when Errors::Refresh # Refresh server list please!
|
144
146
|
# we take this one out of our loop
|
145
147
|
raise
|
146
|
-
when Errors::
|
148
|
+
when Errors::TooBusy # Server is too busy, take the next one
|
147
149
|
next
|
148
150
|
else
|
149
151
|
next
|
data/test/mollom_test.rb
CHANGED
@@ -24,7 +24,7 @@ class TestMollom < Test::Unit::TestCase
|
|
24
24
|
def test_authentication_hash
|
25
25
|
time = mock
|
26
26
|
time.expects(:strftime).with('%Y-%m-%dT%H:%M:%S.000+0000').returns('2008-04-01T13:54:26.000+0000')
|
27
|
-
Time.
|
27
|
+
Time.expects(:now).returns(stub(:gmtime => time))
|
28
28
|
Kernel.expects(:rand).with(2**31).returns(42)
|
29
29
|
hash = @mollom.authentication_hash
|
30
30
|
assert_equal("oWN15TqrbLVdTAgcuDmofskaNyM=", hash[:hash])
|
@@ -36,7 +36,7 @@ class TestMollom < Test::Unit::TestCase
|
|
36
36
|
def test_server_list
|
37
37
|
xml_rpc = mock
|
38
38
|
xml_rpc.expects(:call).with('mollom.getServerList', is_a(Hash)).returns(['http://172.16.0.1', 'http://172.16.0.2', 'https://172.16.0.2'])
|
39
|
-
XMLRPC::Client.
|
39
|
+
XMLRPC::Client.expects(:new).with('xmlrpc.mollom.com', '/1.0').returns(xml_rpc)
|
40
40
|
|
41
41
|
assert_equal [{:ip => '172.16.0.1', :proto => 'http'}, {:ip => '172.16.0.2', :proto => 'http'}, {:ip => '172.16.0.2', :proto => 'https'}], @mollom.server_list
|
42
42
|
end
|
@@ -52,47 +52,54 @@ class TestMollom < Test::Unit::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_send_command_with_good_server
|
55
|
-
Mollom.any_instance.
|
55
|
+
Mollom.any_instance.expects(:server_list).returns([{:ip => '172.16.0.1', :proto => 'http'}])
|
56
56
|
xml_rpc = mock
|
57
57
|
xml_rpc.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo'))
|
58
|
-
XMLRPC::Client.
|
58
|
+
XMLRPC::Client.expects(:new).with('172.16.0.1', '/1.0').returns(xml_rpc)
|
59
59
|
|
60
60
|
@mollom.send_command('mollom.testMessage', {:options => 'foo'})
|
61
61
|
end
|
62
62
|
|
63
63
|
|
64
64
|
def test_send_command_with_bad_server
|
65
|
-
Mollom.any_instance.
|
65
|
+
Mollom.any_instance.expects(:server_list).returns([{:ip => '172.16.0.1', :proto => 'http'}, {:ip => '172.16.0.2', :proto => 'http'}])
|
66
66
|
xml_rpc = mock
|
67
67
|
xml_rpc.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo')).raises(XMLRPC::FaultException.new(1200, "Redirect"))
|
68
68
|
xml_rpc2 = mock
|
69
69
|
xml_rpc2.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo'))
|
70
70
|
|
71
|
-
XMLRPC::Client.
|
72
|
-
XMLRPC::Client.
|
71
|
+
XMLRPC::Client.expects(:new).with('172.16.0.1', '/1.0').returns(xml_rpc)
|
72
|
+
XMLRPC::Client.expects(:new).with('172.16.0.2', '/1.0').returns(xml_rpc2)
|
73
73
|
@mollom.send_command('mollom.testMessage', {:options => 'foo'})
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_send_command_with_reload_exception
|
77
|
-
|
78
|
-
|
77
|
+
Mollom.any_instance.stubs(:server_list).returns([{:ip => '172.16.0.1', :proto => 'http'}], [{:ip => '172.16.0.2', :proto => 'http'}])
|
78
|
+
xml_rpc = mock
|
79
|
+
xml_rpc.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo')).raises(XMLRPC::FaultException.new(1100, "Refresh"))
|
80
|
+
xml_rpc2 = mock
|
81
|
+
xml_rpc2.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo'))
|
82
|
+
|
83
|
+
XMLRPC::Client.expects(:new).with('172.16.0.1', '/1.0').returns(xml_rpc)
|
84
|
+
XMLRPC::Client.expects(:new).with('172.16.0.2', '/1.0').returns(xml_rpc2)
|
85
|
+
@mollom.send_command('mollom.testMessage', {:options => 'foo'})
|
79
86
|
end
|
80
87
|
|
81
88
|
def test_send_command_with_bad_command
|
82
|
-
Mollom.any_instance.
|
89
|
+
Mollom.any_instance.expects(:server_list).returns([{:ip => '172.16.0.1', :proto => 'http'}])
|
83
90
|
xml_rpc = mock
|
84
91
|
xml_rpc.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo')).raises(XMLRPC::FaultException.new(1000, "Fault String"))
|
85
|
-
XMLRPC::Client.
|
92
|
+
XMLRPC::Client.expects(:new).with('172.16.0.1', '/1.0').returns(xml_rpc)
|
86
93
|
|
87
94
|
assert_raise(Mollom::Error) { @mollom.send_command('mollom.testMessage', {:options => 'foo'}) }
|
88
95
|
end
|
89
96
|
|
90
97
|
def test_send_command_with_bad_server_and_no_more_available
|
91
|
-
Mollom.any_instance.
|
98
|
+
Mollom.any_instance.expects(:server_list).returns([{:ip => '172.16.0.1', :proto => 'http'}])
|
92
99
|
xml_rpc = mock
|
93
100
|
xml_rpc.expects(:call).with('mollom.testMessage', has_entry(:options => 'foo')).raises(XMLRPC::FaultException.new(1200, "Redirect"))
|
94
101
|
|
95
|
-
XMLRPC::Client.
|
102
|
+
XMLRPC::Client.expects(:new).with('172.16.0.1', '/1.0').returns(xml_rpc)
|
96
103
|
|
97
104
|
assert_raise(Mollom::NoAvailableServers) { @mollom.send_command('mollom.testMessage', {:options => 'foo'}) }
|
98
105
|
end
|
@@ -122,7 +129,12 @@ class TestMollom < Test::Unit::TestCase
|
|
122
129
|
|
123
130
|
def test_key_ok
|
124
131
|
Mollom.any_instance.expects(:send_command).with('mollom.verifyKey').returns(true)
|
125
|
-
@mollom.key_ok?
|
132
|
+
assert @mollom.key_ok?
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_invalid_key
|
136
|
+
Mollom.any_instance.expects(:send_command).with('mollom.verifyKey').raises(XMLRPC::FaultException.new(1000, "Internal server error due to malformed request, or the hamster powering the server died..."))
|
137
|
+
assert !@mollom.key_ok?
|
126
138
|
end
|
127
139
|
|
128
140
|
def test_statistics
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mollom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan De Poorter
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-06-17 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements: []
|
47
47
|
|
48
48
|
rubyforge_project: mollom
|
49
|
-
rubygems_version: 1.1.
|
49
|
+
rubygems_version: 1.1.1
|
50
50
|
signing_key:
|
51
51
|
specification_version: 2
|
52
52
|
summary: Ruby class for easy interfacing with the mollom.com open API for spam detection and content quality assesment.
|