mikehale-akismet 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/akismet.rb +6 -1
- data/spec/akismet_spec.rb +10 -2
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/akismet.rb
CHANGED
@@ -11,7 +11,12 @@ class Akismet
|
|
11
11
|
@url = url
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def verify?
|
15
|
+
@verified = do_verify unless @verified
|
16
|
+
@verified
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_verify
|
15
20
|
response = Net::HTTP.start('rest.akismet.com', 80) do |http|
|
16
21
|
http.post('/1.1/verify-key', post_data(:key => @key, :blog => @url), {'User-Agent' => USER_AGENT})
|
17
22
|
end
|
data/spec/akismet_spec.rb
CHANGED
@@ -27,16 +27,24 @@ describe "Akismet" do
|
|
27
27
|
it "should verify the key" do
|
28
28
|
map Rack::URLMap.new("http://rest.akismet.com/" => lambda { |env| [200, {}, ["valid"]]})
|
29
29
|
|
30
|
-
@akismet.
|
30
|
+
@akismet.verify?.should == true
|
31
31
|
request.post?.should == true
|
32
32
|
request.env['HTTP_USER_AGENT'].should match(/Akismet-rb\/\d\.\d\.\d/)
|
33
33
|
request.body.should include('http://example.com')
|
34
34
|
response.status.should == 200
|
35
35
|
end
|
36
36
|
|
37
|
+
it "should only verify the key once per instance" do
|
38
|
+
map Rack::URLMap.new("http://rest.akismet.com/" => lambda { |env| [200, {}, ["valid"]]})
|
39
|
+
mock.proxy(Net::HTTP).start(anything, numeric).times(1)
|
40
|
+
|
41
|
+
@akismet.verify?.should == true
|
42
|
+
@akismet.verify?.should == true
|
43
|
+
end
|
44
|
+
|
37
45
|
it "should not verify an invalid key" do
|
38
46
|
map Rack::URLMap.new("http://rest.akismet.com/" => lambda { |env| [200, {'x-akismet-debug-help' => 'sorry!'}, ["invalid"]]})
|
39
|
-
lambda {@akismet.
|
47
|
+
lambda {@akismet.verify?}.should raise_error(Akismet::VerifyException)
|
40
48
|
response['x-akismet-debug-help'].should == 'sorry!'
|
41
49
|
end
|
42
50
|
|