rack-turing-test 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25ecf72d2de79e1601c619baf39ecd9ffd87d6bd
4
- data.tar.gz: d87195ff7397a5cedd3c4546a0b153f8fb48e9d1
3
+ metadata.gz: cb862ed2ca55d74c80a83bf240542671fccf4d96
4
+ data.tar.gz: 9a9c9e4022481fe494a4060bdd7385b8a2e23b11
5
5
  SHA512:
6
- metadata.gz: 20806eb6ecadcea091a6fe2576d5fda89139f0e63001e01b5085427a7b46a550977d9e65ad09a3818a80bb1d4aa74fae81775004bdce30b91e066591d2938886
7
- data.tar.gz: fb09ccdb7bd3495e51fc57d9d8ff89e4f4058af1a4e3a9edef8d0a4eebb3f8e79d9de53b3595994ccfa583a514e5152986233c3182b8c349225913a72461ec5e
6
+ metadata.gz: c089621f20b216bb784f68de6276a07a378aec9ae503203910e6159679d183c3157fd11117e1c915395d64603ac3cc8099950351f14504453bf63f051d332ff1
7
+ data.tar.gz: 0090a820c2ea6ed4677e6d02923e13cb7c14ffad7f89434664fc4ccfa6405964a0e5e7952321c6df4d0fec3f16864cc248ebd1c69e5ce2c18bff92ef1ca1686d
@@ -21,7 +21,17 @@ module Rack
21
21
  # Sometimes, there's a case that the HTTP_USERAGENT is nil.
22
22
  # It's very rare for ordinary browsers. So, simply we observe it as a bot.
23
23
  def bot?
24
- @__bot ||= (user_agent.nil? || !!user_agent.match(PATTERN))
24
+ result = user_agent.nil? || bot!
25
+ ensure
26
+ define_singleton_method(:bot?){result}
27
+ end
28
+
29
+ # Affirmative detection.
30
+ # Returns false if the user agent is nil.
31
+ def bot!
32
+ result = PATTERN === user_agent
33
+ ensure
34
+ define_singleton_method(:bot!){result}
25
35
  end
26
36
  end
27
37
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module TuringTest
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -26,10 +26,16 @@ describe Rack::TuringTest do
26
26
  req.should be_bot
27
27
  end
28
28
 
29
+ it "don't detect requests that the ua is nil as bot affirmatively" do
30
+ req = TestRequest.new nil
31
+ req.bot!.should be_false
32
+ end
33
+
29
34
  it "can detect googlebot (no ajax)" do
30
35
  ua = "Mediapartners-Google"
31
36
  req = TestRequest.new ua
32
37
  req.should be_bot
38
+ req.bot!.should be_true
33
39
  end
34
40
 
35
41
  it "can detect googlebot (ajax)" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-turing-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Takiuchi