browsernizer 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7dd10a5602dbe925a6e861a29820259986292e83
4
+ data.tar.gz: 1a2602a4e5bda131e7f72a0d20a168e3bac2d079
5
+ SHA512:
6
+ metadata.gz: 94f21d35f5197a663cf05a7b402f23bc8e596a65fe2df01b0bfe40f16756f272b8a281322250c2cd31b6554fe2f3af17ff477d4be77f1f19c7580e5ff8d7058d
7
+ data.tar.gz: cb828676b75e87b317ce6b8d57c66961d6b1af7364cba1f865c67fe3f964b11fc6fda780bc97cbab4bb21eb4a5e5fdf01d853445a3aa81ed6837a4b964efcf9a
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ = Version 0.2.3
2
+ * Allow arbitrary include/exclude logic - #13 by @romanbsd
3
+
1
4
  = Version 0.2.2
2
5
  * Relax version dependency of the 'browser' gem - by @adammck
3
6
 
data/README.md CHANGED
@@ -57,6 +57,17 @@ can declare it like this:
57
57
  !(browser.name == "Safari" && browser.mobile?)
58
58
  end
59
59
 
60
+ The block should return false to block the browser, true to allow it, and nil if it
61
+ cannot decide. This way you can make any arbitrary User-Agent explicitly allowed,
62
+ even if its version would have been blocked otherwise:
63
+
64
+ config.supported do |browser|
65
+ true if browser.user_agent.include?('Linux')
66
+ end
67
+
68
+ Please note, that the order is important, thus the first block or requirement returning
69
+ a boolean wins.
70
+
60
71
  Specifying location is optional. If you prefer handling unsupported browsers on
61
72
  your own, you can access browsernizer info from `request.env['browsernizer']`
62
73
  within your controller.
@@ -54,13 +54,14 @@ module Browsernizer
54
54
 
55
55
  # supported by default
56
56
  def supported?(raw_browser, browser)
57
- !@config.get_supported.any? do |requirement|
57
+ @config.get_supported.inject(true) do |default, requirement|
58
58
  supported = if requirement.respond_to?(:call)
59
59
  requirement.call(raw_browser)
60
60
  else
61
61
  browser.meets?(requirement)
62
62
  end
63
- supported === false
63
+ break supported unless supported.nil?
64
+ default
64
65
  end
65
66
  end
66
67
  end
@@ -1,3 +1,3 @@
1
1
  module Browsernizer
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -5,18 +5,18 @@ describe Browsernizer::Browser do
5
5
  describe "#meets?(requirement)" do
6
6
  context "same vendor" do
7
7
  it "returns true if version is >= to requirement" do
8
- browser("Chrome", "10.0").meets?(browser("Chrome", "10" )).should be_true
9
- browser("Chrome", "10.0").meets?(browser("Chrome", "10.1")).should be_false
10
- browser("Chrome", "10" ).meets?(browser("Chrome", " 9.1")).should be_true
8
+ expect(browser("Chrome", "10.0").meets?(browser("Chrome", "10" ))).to be_true
9
+ expect(browser("Chrome", "10.0").meets?(browser("Chrome", "10.1"))).to be_false
10
+ expect(browser("Chrome", "10" ).meets?(browser("Chrome", " 9.1"))).to be_true
11
11
  end
12
12
  it "returns false if requirement version is set to false" do
13
- browser("Chrome", "10" ).meets?(browser("Chrome", false )).should be_false
13
+ expect(browser("Chrome", "10" ).meets?(browser("Chrome", false ))).to be_false
14
14
  end
15
15
  end
16
16
 
17
17
  context "different vendors" do
18
18
  it "returns nil" do
19
- browser("Chrome", "10").meets?(browser("Firefox", "10")).should be_nil
19
+ expect(browser("Chrome", "10").meets?(browser("Firefox", "10"))).to be_nil
20
20
  end
21
21
  end
22
22
  end
@@ -5,20 +5,20 @@ describe Browsernizer::BrowserVersion do
5
5
  describe "Comparable" do
6
6
 
7
7
  it "is greater" do
8
- version("2").should > version("1")
9
- version("1.1").should > version("1")
10
- version("1.1").should > version("1.0")
11
- version("2").should > version("1.9")
8
+ expect(version("2")).to be > version("1")
9
+ expect(version("1.1")).to be > version("1")
10
+ expect(version("1.1")).to be > version("1.0")
11
+ expect(version("2")).to be > version("1.9")
12
12
  end
13
13
 
14
14
  it "is equal" do
15
- version("1").should == version("1")
16
- version("1").should == version("1.0")
17
- version("1.0").should == version("1")
15
+ expect(version("1")).to eq(version("1"))
16
+ expect(version("1")).to eq(version("1.0"))
17
+ expect(version("1.0")).to eq(version("1"))
18
18
  end
19
19
 
20
20
  it "handles strings" do
21
- version("1.0").should == version("1.0.alpha")
21
+ expect(version("1.0")).to eq(version("1.0.alpha"))
22
22
  end
23
23
 
24
24
  end
@@ -8,19 +8,19 @@ describe Browsernizer::Config do
8
8
  it "defines new supported browser" do
9
9
  subject.supported "Chrome", "16.0"
10
10
  subject.supported "Firefox", "10.0"
11
- subject.get_supported.should have(2).items
11
+ expect(subject.get_supported.size).to eq(2)
12
12
  end
13
13
 
14
14
  it "allows to unsupport browser by using false as version number" do
15
15
  subject.supported "Chrome", false
16
- subject.get_supported[0].version.should be_false
16
+ expect(subject.get_supported[0].version).to be_false
17
17
  end
18
18
  end
19
19
 
20
20
  describe "location(path)" do
21
21
  it "sets the redirection path for unsupported browsers" do
22
22
  subject.location "foo.html"
23
- subject.get_location.should == "foo.html"
23
+ expect(subject.get_location).to eq("foo.html")
24
24
  end
25
25
  end
26
26
 
@@ -29,11 +29,11 @@ describe Browsernizer::Config do
29
29
  subject.exclude %r{^/assets}
30
30
  subject.exclude "/foo/bar.html"
31
31
 
32
- subject.excluded?("/assets/foo.jpg").should be_true
33
- subject.excluded?("/Assets/foo.jpg").should be_false
34
- subject.excluded?("/prefix/assets/foo.jpg").should be_false
35
- subject.excluded?("/foo/bar.html").should be_true
36
- subject.excluded?("/foo/bar2.html").should be_false
32
+ expect(subject.excluded?("/assets/foo.jpg")).to be_true
33
+ expect(subject.excluded?("/Assets/foo.jpg")).to be_false
34
+ expect(subject.excluded?("/prefix/assets/foo.jpg")).to be_false
35
+ expect(subject.excluded?("/foo/bar.html")).to be_true
36
+ expect(subject.excluded?("/foo/bar2.html")).to be_false
37
37
  end
38
38
  end
39
39
 
@@ -6,6 +6,9 @@ describe Browsernizer::Router do
6
6
 
7
7
  subject do
8
8
  Browsernizer::Router.new(app) do |config|
9
+ config.supported do |browser|
10
+ true if browser.user_agent.include?('Spec')
11
+ end
9
12
  config.supported "Firefox", false
10
13
  config.supported "Chrome", "7.1"
11
14
  config.supported do |browser|
@@ -22,11 +25,11 @@ describe Browsernizer::Router do
22
25
  end
23
26
 
24
27
  context "All Good" do
25
- it "propagates requrest with updated env" do
26
- app.should_receive(:call).with do |env|
27
- env['browsernizer']['supported'].should be_true
28
- env['browsernizer']['browser'].should == "Chrome"
29
- env['browsernizer']['version'].should == "7.1.1"
28
+ it "propagates request with updated env" do
29
+ expect(app).to receive(:call) do |env|
30
+ expect(env['browsernizer']['supported']).to be_true
31
+ expect(env['browsernizer']['browser']).to eq("Chrome")
32
+ expect(env['browsernizer']['version']).to eq("7.1.1")
30
33
  end
31
34
  subject.call(default_env)
32
35
  end
@@ -35,9 +38,9 @@ describe Browsernizer::Router do
35
38
 
36
39
  shared_examples "unsupported browser" do
37
40
  context "location not set" do
38
- it "propagates requrest with updated env" do
39
- app.should_receive(:call).with do |env|
40
- env['browsernizer']['supported'].should be_false
41
+ it "propagates request with updated env" do
42
+ expect(app).to receive(:call) do |env|
43
+ expect(env['browsernizer']['supported']).to be_false
41
44
  end
42
45
  subject.call(@env)
43
46
  end
@@ -49,14 +52,14 @@ describe Browsernizer::Router do
49
52
  end
50
53
 
51
54
  it "prevents propagation" do
52
- app.should_not_receive(:call)
55
+ expect(app).not_to receive(:call)
53
56
  subject.call(@env)
54
57
  end
55
58
 
56
59
  it "redirects to proper location" do
57
60
  response = subject.call(@env)
58
- response[0].should == 307
59
- response[1]["Location"].should == "/browser.html"
61
+ expect(response[0]).to eq(307)
62
+ expect(response[1]["Location"]).to eq("/browser.html")
60
63
  end
61
64
 
62
65
  context "Excluded path" do
@@ -67,7 +70,7 @@ describe Browsernizer::Router do
67
70
  })
68
71
  end
69
72
  it "propagates request" do
70
- app.should_receive(:call).with(@env)
73
+ expect(app).to receive(:call).with(@env)
71
74
  subject.call(@env)
72
75
  end
73
76
  end
@@ -78,9 +81,9 @@ describe Browsernizer::Router do
78
81
  "PATH_INFO" => "/browser.html"
79
82
  })
80
83
  end
81
- it "propagates requrest with updated env" do
82
- app.should_receive(:call).with do |env|
83
- env['browsernizer']['supported'].should be_false
84
+ it "propagates request with updated env" do
85
+ expect(app).to receive(:call) do |env|
86
+ expect(env['browsernizer']['supported']).to be_false
84
87
  end
85
88
  subject.call(@env)
86
89
  end
@@ -115,6 +118,21 @@ describe Browsernizer::Router do
115
118
  it_behaves_like "unsupported browser"
116
119
  end
117
120
 
121
+ context "Supported by proc" do
122
+ before do
123
+ @env = default_env.merge({
124
+ "HTTP_USER_AGENT" => firefox_agent("10.0.1") + ' Spec'
125
+ })
126
+ end
127
+
128
+ it "propagates request" do
129
+ expect(app).to receive(:call) do |env|
130
+ expect(env['browsernizer']['supported']).to be_true
131
+ end
132
+ subject.call(@env)
133
+ end
134
+ end
135
+
118
136
  def chrome_agent(version)
119
137
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/#{version} Safari/535.7"
120
138
  end
metadata CHANGED
@@ -1,49 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsernizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.2.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Milovan Zogovic
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-30 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- requirement: &70242799782200 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70242799782200
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rspec
27
- requirement: &70242799781760 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70242799781760
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: browser
38
- requirement: &70242799781200 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>'
45
+ - - ">"
42
46
  - !ruby/object:Gem::Version
43
47
  version: 0.1.4
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *70242799781200
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.4
47
55
  description: Rack middleware for redirecting unsupported user agents to "please upgrade"
48
56
  page
49
57
  email:
@@ -52,7 +60,7 @@ executables: []
52
60
  extensions: []
53
61
  extra_rdoc_files: []
54
62
  files:
55
- - .gitignore
63
+ - ".gitignore"
56
64
  - CHANGELOG
57
65
  - Gemfile
58
66
  - LICENSE
@@ -74,33 +82,26 @@ files:
74
82
  - spec/spec_helper.rb
75
83
  homepage: ''
76
84
  licenses: []
85
+ metadata: {}
77
86
  post_install_message:
78
87
  rdoc_options: []
79
88
  require_paths:
80
89
  - lib
81
90
  required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
91
  requirements:
84
- - - ! '>='
92
+ - - ">="
85
93
  - !ruby/object:Gem::Version
86
94
  version: '0'
87
- segments:
88
- - 0
89
- hash: 2510847936117129641
90
95
  required_rubygems_version: !ruby/object:Gem::Requirement
91
- none: false
92
96
  requirements:
93
- - - ! '>='
97
+ - - ">="
94
98
  - !ruby/object:Gem::Version
95
99
  version: '0'
96
- segments:
97
- - 0
98
- hash: 2510847936117129641
99
100
  requirements: []
100
101
  rubyforge_project: browsernizer
101
- rubygems_version: 1.8.11
102
+ rubygems_version: 2.4.2
102
103
  signing_key:
103
- specification_version: 3
104
+ specification_version: 4
104
105
  summary: Want friendly "please upgrade your browser" page? This gem is for you.
105
106
  test_files:
106
107
  - spec/browsernizer/browser_spec.rb