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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 0
data/lib/akismet.rb CHANGED
@@ -11,7 +11,12 @@ class Akismet
11
11
  @url = url
12
12
  end
13
13
 
14
- def verify_key
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.verify_key.should == true
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.verify_key}.should raise_error(Akismet::VerifyException)
47
+ lambda {@akismet.verify?}.should raise_error(Akismet::VerifyException)
40
48
  response['x-akismet-debug-help'].should == 'sorry!'
41
49
  end
42
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikehale-akismet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hale