rack-smartphone_detector 0.0.3 → 0.0.4

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.
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  module Rack
3
3
  class SmartphoneDetector
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
6
6
  end
@@ -9,7 +9,7 @@ module Rack
9
9
  SMARTPHONE_IDENTIFIERS = [
10
10
  { identifier: 'iPhone', regexp: /iPhone/ },
11
11
  { identifier: 'iPad', regexp: /iPad/ },
12
- { identifier: 'Android', regexp: /Android.+Mobile/ },
12
+ { identifier: 'Android', regexp: /Android.+Mobi(le)?/ },
13
13
  { identifier: 'Android Tablet', regexp: /Android/ },
14
14
  { identifier: 'Windows Phone', regexp: /Windows Phone/ },
15
15
  ]
@@ -7,11 +7,38 @@ describe 'Rack::SmartphoneDetector' do
7
7
  include Rack::Test::Methods
8
8
 
9
9
  SMARTPHONES = [
10
- { name: 'iPhone', user_agent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25' },
11
- { name: 'iPad', user_agent: 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25' },
12
- { name: 'Android', user_agent: 'Mozilla/5.0 (Linux; U; Android 4.0.1; ja-jp; Galaxy Nexus Build/ITL41D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30' },
13
- { name: 'Android Tablet', user_agent: 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03S) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19' },
14
- { name: 'Windows Phone', user_agent: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; FujitsuToshibaMobileCommun; IS12T; KDDI)' }
10
+ {
11
+ name: 'iPhone',
12
+ user_agents: [
13
+ 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25',
14
+ ]
15
+ },
16
+ {
17
+ name: 'iPad',
18
+ user_agents: [
19
+ 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25'
20
+ ]
21
+ },
22
+ {
23
+ name: 'Android',
24
+ user_agents: [
25
+ 'Mozilla/5.0 (Linux; U; Android 4.0.1; ja-jp; Galaxy Nexus Build/ITL41D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
26
+ 'Mozilla/5.0 (Android; Mobile; rv:18.0) Gecko/18.0 Firefox/18.0',
27
+ 'Opera/9.80 (Android 4.2.1; Linux; Opera Mobi/ADR-1301080958) Presto/2.11.355 Version/12.10'
28
+ ]
29
+ },
30
+ {
31
+ name: 'Android Tablet',
32
+ user_agents: [
33
+ 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03S) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19'
34
+ ]
35
+ },
36
+ {
37
+ name: 'Windows Phone',
38
+ user_agents: [
39
+ 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; FujitsuToshibaMobileCommun; IS12T; KDDI)'
40
+ ]
41
+ }
15
42
  ]
16
43
 
17
44
  let(:app) do
@@ -21,25 +48,34 @@ describe 'Rack::SmartphoneDetector' do
21
48
 
22
49
  it 'sets environment variable if the request comes from smartphone' do
23
50
  SMARTPHONES.each do |info|
24
- header 'User-Agent', info[:user_agent]
25
- get '/'
26
- last_request.env['rack.smartphone_detector.device'].must_equal info[:name]
51
+ info[:user_agents].each do |ua|
52
+ header 'User-Agent', ua
53
+ get '/'
54
+ last_request.env['rack.smartphone_detector.device'].must_equal info[:name]
55
+ end
27
56
  end
28
57
  end
29
58
 
30
59
  describe '#from_smartphone?' do
31
60
  it 'returns true if the request comes from smartphone' do
32
61
  SMARTPHONES.each do |info|
33
- header 'User-Agent', info[:user_agent]
34
- get '/'
35
- last_request.from_smartphone?.must_equal true
62
+ info[:user_agents].each do |ua|
63
+ header 'User-Agent', ua
64
+ get '/'
65
+ last_request.from_smartphone?.must_equal true
66
+ end
36
67
  end
37
68
  end
38
69
 
39
70
  it 'returns false if the request does not come from smartphone' do
40
- header 'User-Agent', 'DoCoMo/2.0 F01E(c500;TB;W24H16)'
41
- get '/'
42
- last_request.from_smartphone?.must_equal false
71
+ [
72
+ 'DoCoMo/2.0 F01E(c500;TB;W24H16)',
73
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11'
74
+ ].each do |ua|
75
+ header 'User-Agent', ua
76
+ get '/'
77
+ last_request.from_smartphone?.must_equal false
78
+ end
43
79
  end
44
80
 
45
81
  it 'returns false if the request comes from device without user-agent' do
@@ -50,45 +86,55 @@ describe 'Rack::SmartphoneDetector' do
50
86
 
51
87
  describe '#from_iphone?' do
52
88
  it 'returns true if the request comes from iphone' do
53
- header 'User-Agent', user_agent('iPhone')
54
- get '/'
55
- last_request.from_iphone?.must_equal true
89
+ user_agents('iPhone').each do |ua|
90
+ header 'User-Agent', ua
91
+ get '/'
92
+ last_request.from_iphone?.must_equal true
93
+ end
56
94
  end
57
95
  end
58
96
 
59
97
  describe '#from_ipad?' do
60
98
  it 'returns true if the request comes from ipad' do
61
- header 'User-Agent', user_agent('iPad')
62
- get '/'
63
- last_request.from_ipad?.must_equal true
99
+ user_agents('iPad').each do |ua|
100
+ header 'User-Agent', ua
101
+ get '/'
102
+ last_request.from_ipad?.must_equal true
103
+ end
64
104
  end
65
105
  end
66
106
 
67
107
  describe '#from_android?' do
68
108
  it 'returns true if the request comes from android mobile' do
69
- header 'User-Agent', user_agent('Android')
70
- get '/'
71
- last_request.from_android?.must_equal true
109
+ user_agents('Android').each do |ua|
110
+ header 'User-Agent', ua
111
+ get '/'
112
+ last_request.from_android?.must_equal true
113
+ end
72
114
  end
73
115
  end
74
116
 
75
117
  describe '#from_android_tablet?' do
76
118
  it 'returns true if the request comes from android tablet' do
77
- header 'User-Agent', user_agent('Android Tablet')
78
- get '/'
79
- last_request.from_android_tablet?.must_equal true
119
+ user_agents('Android Tablet').each do |ua|
120
+ header 'User-Agent', ua
121
+ get '/'
122
+ last_request.from_android_tablet?.must_equal true
123
+ end
80
124
  end
81
125
  end
82
126
 
83
127
  describe '#from_windows_phone?' do
84
128
  it 'returns true if the request comes from windows phone' do
85
- header 'User-Agent', user_agent('Windows Phone')
86
- get '/'
87
- last_request.from_windows_phone?.must_equal true
129
+ user_agents('Windows Phone').each do |ua|
130
+ header 'User-Agent', ua
131
+ get '/'
132
+ last_request.from_windows_phone?.must_equal true
133
+ end
88
134
  end
89
135
  end
90
136
 
91
- def user_agent(name)
92
- SMARTPHONES.find { |info| info[:name] == name }[:user_agent]
137
+ def user_agents(name)
138
+ SMARTPHONES.find { |info| info[:name] == name }[:user_agents]
93
139
  end
94
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-smartphone_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-15 00:00:00.000000000 Z
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -108,18 +108,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- segments:
112
- - 0
113
- hash: 4226079495124680780
114
111
  required_rubygems_version: !ruby/object:Gem::Requirement
115
112
  none: false
116
113
  requirements:
117
114
  - - ! '>='
118
115
  - !ruby/object:Gem::Version
119
116
  version: '0'
120
- segments:
121
- - 0
122
- hash: 4226079495124680780
123
117
  requirements: []
124
118
  rubyforge_project:
125
119
  rubygems_version: 1.8.23