browser 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require "test_helper"
2
+ require "browser/rails"
3
+ require "sample_app"
4
+
5
+ class MiddlewareTest < Test::Unit::TestCase
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ Rails.application
10
+ end
11
+
12
+ def test_redirect_ie6_to_upgrade_path
13
+ get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6"}
14
+ follow_redirect!
15
+
16
+ assert_equal "UPGRADE: ie6", last_response.body
17
+ end
18
+
19
+ def test_redirect_ie7_to_upgrade_path
20
+ get "/", {}, {"HTTP_USER_AGENT" => "MSIE 7"}
21
+ follow_redirect!
22
+
23
+ assert_equal "UPGRADE: ie7", last_response.body
24
+ end
25
+
26
+ def test_redirect_ie8_and_404
27
+ get "/", {}, {"HTTP_USER_AGENT" => "MSIE 8"}
28
+ follow_redirect!
29
+
30
+ assert_equal 404, last_response.status
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ require "rails"
2
+ require "browser"
3
+
4
+ class SampleApp < Rails::Application
5
+ config.secret_token = "99f19f08db7a37bdcb9d6701f54dca"
6
+ config.secret_key_base = "99f19f08db7a37bdcb9d6701f54dca"
7
+ config.eager_load = true
8
+ config.active_support.deprecation = :log
9
+
10
+ routes.append do
11
+ default_headers = {"Content-Type" => "text/html"}
12
+
13
+ root to: -> env { [200, default_headers, ["ROOT"]] }
14
+ get "upgrade", to: -> env {
15
+ browser = Rack::Request.new(env).params["browser"]
16
+ [200, default_headers, ["UPGRADE: #{browser}"]]
17
+ }, as: "upgrade"
18
+ end
19
+
20
+ config.middleware.use Browser::Middleware do
21
+ redirect_to upgrade_path(browser: "ie6") if browser.ie6?
22
+ redirect_to upgrade_path(browser: "ie7") if browser.ie7?
23
+ redirect_to "/invalid" if browser.ie8?
24
+ end
25
+ end
26
+
27
+ SampleApp.initialize!
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
2
+ require "bundler/setup"
1
3
  require "test/unit"
2
- require "action_controller"
3
4
  require "browser"
metadata CHANGED
@@ -1,94 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nando Vieira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
11
+ date: 2013-06-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: actionpack
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: rdoc
14
+ name: pry-meta
48
15
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
16
  requirements:
51
- - - ! '>='
17
+ - - '>='
52
18
  - !ruby/object:Gem::Version
53
19
  version: '0'
54
20
  type: :development
55
21
  prerelease: false
56
22
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
23
  requirements:
59
- - - ! '>='
24
+ - - '>='
60
25
  - !ruby/object:Gem::Version
61
26
  version: '0'
62
27
  - !ruby/object:Gem::Dependency
63
- name: pry-meta
28
+ name: rails
64
29
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
30
  requirements:
67
- - - ! '>='
31
+ - - '>='
68
32
  - !ruby/object:Gem::Version
69
33
  version: '0'
70
34
  type: :development
71
35
  prerelease: false
72
36
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
37
  requirements:
75
- - - ! '>='
38
+ - - '>='
76
39
  - !ruby/object:Gem::Version
77
40
  version: '0'
78
41
  - !ruby/object:Gem::Dependency
79
- name: awesome_print
42
+ name: rack-test
80
43
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
44
  requirements:
83
- - - ! '>='
45
+ - - '>='
84
46
  - !ruby/object:Gem::Version
85
47
  version: '0'
86
48
  type: :development
87
49
  prerelease: false
88
50
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
51
  requirements:
91
- - - ! '>='
52
+ - - '>='
92
53
  - !ruby/object:Gem::Version
93
54
  version: '0'
94
55
  description: Do some browser detection with Ruby.
@@ -99,38 +60,63 @@ extensions: []
99
60
  extra_rdoc_files: []
100
61
  files:
101
62
  - .gitignore
63
+ - .travis.yml
102
64
  - Gemfile
103
65
  - Gemfile.lock
104
- - README.rdoc
66
+ - README.md
105
67
  - Rakefile
106
68
  - browser.gemspec
69
+ - config.ru
70
+ - gemfiles/rails3.gemfile
71
+ - gemfiles/rails3.gemfile.lock
107
72
  - lib/browser.rb
108
73
  - lib/browser/action_controller.rb
74
+ - lib/browser/meta/base.rb
75
+ - lib/browser/meta/generic_browser.rb
76
+ - lib/browser/meta/id.rb
77
+ - lib/browser/meta/ie.rb
78
+ - lib/browser/meta/ios.rb
79
+ - lib/browser/meta/mobile.rb
80
+ - lib/browser/meta/modern.rb
81
+ - lib/browser/meta/platform.rb
82
+ - lib/browser/meta/safari.rb
83
+ - lib/browser/meta/webkit.rb
84
+ - lib/browser/methods/devices.rb
85
+ - lib/browser/methods/ie.rb
86
+ - lib/browser/methods/language.rb
87
+ - lib/browser/methods/mobile.rb
88
+ - lib/browser/methods/platform.rb
89
+ - lib/browser/middleware.rb
90
+ - lib/browser/middleware/context.rb
91
+ - lib/browser/middleware/context/additions.rb
92
+ - lib/browser/middleware/context/url_methods.rb
93
+ - lib/browser/rails.rb
109
94
  - lib/browser/version.rb
110
95
  - test/browser_test.rb
96
+ - test/middleware_test.rb
97
+ - test/sample_app.rb
111
98
  - test/test_helper.rb
112
99
  homepage: http://github.com/fnando/browser
113
100
  licenses: []
101
+ metadata: {}
114
102
  post_install_message:
115
103
  rdoc_options: []
116
104
  require_paths:
117
105
  - lib
118
106
  required_ruby_version: !ruby/object:Gem::Requirement
119
- none: false
120
107
  requirements:
121
- - - ! '>='
108
+ - - '>='
122
109
  - !ruby/object:Gem::Version
123
110
  version: '0'
124
111
  required_rubygems_version: !ruby/object:Gem::Requirement
125
- none: false
126
112
  requirements:
127
- - - ! '>='
113
+ - - '>='
128
114
  - !ruby/object:Gem::Version
129
115
  version: '0'
130
116
  requirements: []
131
117
  rubyforge_project:
132
- rubygems_version: 1.8.25
118
+ rubygems_version: 2.0.3
133
119
  signing_key:
134
- specification_version: 3
120
+ specification_version: 4
135
121
  summary: Do some browser detection with Ruby.
136
122
  test_files: []
data/README.rdoc DELETED
@@ -1,75 +0,0 @@
1
- = Browser
2
-
3
- Do some browser detection with Ruby. Includes ActionController integration.
4
-
5
- == Installation
6
-
7
- gem install browser
8
-
9
- == Usage
10
-
11
- require "rubygems"
12
- require "browser"
13
-
14
- browser = Browser.new(:ua => "some string", :accept_language => "en-us")
15
- browser.name # readable browser name
16
- browser.safari?
17
- browser.opera?
18
- browser.chrome?
19
- browser.mobile?
20
- browser.firefox?
21
- browser.ie?
22
- browser.ie6? # this goes up to 9
23
- browser.capable? # supports some CSS 3
24
- browser.platform # return :mac, :windows, :linux or :other
25
- browser.mac?
26
- browser.windows?
27
- browser.linux?
28
- browser.meta # an array with several attributes
29
- browser.to_s # the meta info joined by space
30
-
31
- See the tests for more examples.
32
-
33
- === Rails integration
34
-
35
- Just add it to the Gemfile or `environment.rb`, depending of your Rails version.
36
-
37
- gem "browser" #=> Rails 3
38
- config.gem "browser" #=> Rails 2
39
-
40
- This adds a helper method called `browser`, that inspects your current user agent.
41
-
42
- <% if browser.ie6? %>
43
- <p class="disclaimer">You're running an older IE version. Please update it!</p>
44
- <% end %>
45
-
46
- == Maintainer
47
-
48
- * Nando Vieira - http://nandovieira.com.br
49
-
50
- == Contributors
51
-
52
- * http://github.com/chrisyour/browser
53
-
54
- == License
55
-
56
- (The MIT License)
57
-
58
- Permission is hereby granted, free of charge, to any person obtaining
59
- a copy of this software and associated documentation files (the
60
- 'Software'), to deal in the Software without restriction, including
61
- without limitation the rights to use, copy, modify, merge, publish,
62
- distribute, sublicense, and/or sell copies of the Software, and to
63
- permit persons to whom the Software is furnished to do so, subject to
64
- the following conditions:
65
-
66
- The above copyright notice and this permission notice shall be
67
- included in all copies or substantial portions of the Software.
68
-
69
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.