rack-turing-test 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/lib/rack-turing-test.rb +11 -1
- data/lib/rack-turing-test/version.rb +1 -1
- data/spec/rack_turing_test_spec.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb862ed2ca55d74c80a83bf240542671fccf4d96
|
4
|
+
data.tar.gz: 9a9c9e4022481fe494a4060bdd7385b8a2e23b11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c089621f20b216bb784f68de6276a07a378aec9ae503203910e6159679d183c3157fd11117e1c915395d64603ac3cc8099950351f14504453bf63f051d332ff1
|
7
|
+
data.tar.gz: 0090a820c2ea6ed4677e6d02923e13cb7c14ffad7f89434664fc4ccfa6405964a0e5e7952321c6df4d0fec3f16864cc248ebd1c69e5ce2c18bff92ef1ca1686d
|
data/lib/rack-turing-test.rb
CHANGED
@@ -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
|
-
|
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
|
|
@@ -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
|