device_detector 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe DeviceDetector::Device do
4
+
5
+ subject(:device) { DeviceDetector::Device.new(user_agent) }
6
+
7
+ describe '#name' do
8
+
9
+ context 'when models are nested' do
10
+ let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]' }
11
+
12
+ it 'finds an Apple iPhone 6' do
13
+ expect(device.name).to eq('iPhone 6')
14
+ end
15
+ end
16
+
17
+ context 'when models are NOT nested' do
18
+ let(:user_agent) { 'AIRNESS-AIR99/REV 2.2.1/Teleca Q03B1' }
19
+
20
+ it 'finds an Airness AIR99' do
21
+ expect(device.name).to eq('AIR99')
22
+ end
23
+ end
24
+
25
+ context 'when it cannot find a device name' do
26
+ let(:user_agent) { 'UNKNOWN MODEL NAME' }
27
+
28
+ it 'returns nil' do
29
+ expect(device.name).to eq(nil)
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ describe '#type' do
36
+
37
+ context 'when models are nested' do
38
+ let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]' }
39
+
40
+ it 'finds device of Apple iPhone 6' do
41
+ expect(device.type).to eq('smartphone')
42
+ end
43
+ end
44
+
45
+ context 'when models are NOT nested' do
46
+ let(:user_agent) { 'AIRNESS-AIR99/REV 2.2.1/Teleca Q03B1' }
47
+
48
+ it 'finds the device of Airness AIR99' do
49
+ expect(device.type).to eq('feature phone')
50
+ end
51
+ end
52
+
53
+ context 'when it cannot find a device type' do
54
+ let(:user_agent) { 'UNKNOWN MODEL TYPE' }
55
+
56
+ it 'returns nil' do
57
+ expect(device.type).to eq(nil)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe DeviceDetector::ModelExtractor do
4
+
5
+ subject(:extractor) { DeviceDetector::ModelExtractor.new(user_agent, regex_meta) }
6
+
7
+ describe '#call' do
8
+
9
+ context 'when matching against dynamic model' do
10
+
11
+ let(:regex_meta) do
12
+ {
13
+ 'regex' => '(?:Apple-)?iPhone ?(3GS?|4S?|5[CS]?|6(:? Plus)?)?',
14
+ 'model' => 'iPhone $1',
15
+ 'device' => 'smartphone'
16
+ }
17
+ end
18
+
19
+ context 'when no dynamic match is found' do
20
+ let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4' }
21
+ let(:device_name) { 'iPhone' }
22
+
23
+ it 'returns the textual portion without trailing whitespace' do
24
+ expect(extractor.call).to eq(device_name)
25
+ end
26
+
27
+ end
28
+
29
+ context 'when a dynamic match is found' do
30
+ let(:user_agent) { 'Mozilla/5.0 (iPhone 5S; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4' }
31
+ let(:device_name) { 'iPhone 5S' }
32
+
33
+ it 'returns the full device name' do
34
+ expect(extractor.call).to eq(device_name)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ context 'when matching against static model' do
42
+
43
+ let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12A365 Weibo (iPhone7,2)' }
44
+ let(:device_name) { 'iPhone 6' }
45
+ let(:regex_meta) do
46
+ {
47
+ 'regex' => '(?:Apple-)?iPhone7[C,]2',
48
+ 'model' => 'iPhone 6',
49
+ 'device' => 'smartphone'
50
+ }
51
+ end
52
+
53
+ it 'returns the model name' do
54
+ expect(extractor.call).to eq(device_name)
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -27,6 +27,7 @@ RSpec.describe DeviceDetector::VersionExtractor do
27
27
  context 'regex with dynamic matching' do
28
28
 
29
29
  let(:user_agent) { 'Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.8.1b2) Gecko/20060821 BonEcho/2.0b2 (Debian-1.99+2.0b2+dfsg-1)' }
30
+ let(:version) { 'BonEcho (2.0)' }
30
31
  let(:regex_meta) do
31
32
  {
32
33
  'regex' => '(BonEcho|GranParadiso|Lorentz|Minefield|Namoroka|Shiretoko)/(\d+[\.\d]+)',
@@ -36,7 +37,12 @@ RSpec.describe DeviceDetector::VersionExtractor do
36
37
  end
37
38
 
38
39
  it 'returns the correct version' do
39
- expect(extractor.call).to eq('BonEcho (2.0)')
40
+ expect(extractor.call).to eq(version)
41
+ end
42
+
43
+ it 'removes trailing white spaces' do
44
+ regex_meta['version'] = regex_meta['version'] + ' '
45
+ expect(extractor.call).to eq(version)
40
46
  end
41
47
 
42
48
  end
@@ -6,60 +6,86 @@ RSpec.describe DeviceDetector do
6
6
 
7
7
  context 'known user agent' do
8
8
 
9
- let(:user_agent) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69' }
9
+ context 'desktop chrome browser' do
10
10
 
11
- describe '#name' do
11
+ let(:user_agent) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69' }
12
+
13
+ describe '#name' do
14
+
15
+ it 'returns the name' do
16
+ expect(client.name).to eq('Chrome')
17
+ end
12
18
 
13
- it 'returns the name' do
14
- expect(client.name).to eq('Chrome')
15
19
  end
16
20
 
17
- end
21
+ describe '#full_version' do
18
22
 
19
- describe '#full_version' do
23
+ it 'returns the full version' do
24
+ expect(client.full_version).to eq('30.0.1599.69')
25
+ end
20
26
 
21
- it 'returns the full version' do
22
- expect(client.full_version).to eq('30.0.1599.69')
23
27
  end
24
28
 
25
- end
29
+ describe '#os_name' do
26
30
 
27
- describe '#os_name' do
31
+ it 'returns the operating system name' do
32
+ expect(client.os_name).to eq('Mac')
33
+ end
28
34
 
29
- it 'returns the operating system name' do
30
- expect(client.os_name).to eq('Mac')
31
35
  end
32
36
 
33
- end
37
+ describe '#os_full_version' do
34
38
 
35
- describe '#os_full_version' do
39
+ it 'returns the operating system full version' do
40
+ expect(client.os_full_version).to eq('10_8_5')
41
+ end
36
42
 
37
- it 'returns the operating system full version' do
38
- expect(client.os_full_version).to eq('10_8_5')
39
43
  end
40
44
 
41
- end
45
+ describe '#known?' do
42
46
 
43
- describe '#known?' do
47
+ it 'returns true' do
48
+ expect(client.known?).to eq(true)
49
+ end
44
50
 
45
- it 'returns true' do
46
- expect(client.known?).to eq(true)
47
51
  end
48
52
 
49
- end
53
+ describe '#bot?' do
50
54
 
51
- describe '#bot?' do
55
+ it 'returns false' do
56
+ expect(client.bot?).to eq(false)
57
+ end
58
+
59
+ end
60
+
61
+ describe '#bot_name' do
62
+
63
+ it 'returns nil' do
64
+ expect(client.bot_name).to be_nil
65
+ end
52
66
 
53
- it 'returns false' do
54
- expect(client.bot?).to eq(false)
55
67
  end
56
68
 
57
69
  end
58
70
 
59
- describe '#bot_name' do
71
+ context 'mobile iPhone 5S' do
72
+
73
+ let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B440 [FBDV/iPhone6,1]' }
74
+
75
+ describe '#device_name' do
76
+
77
+ it 'returns device name' do
78
+ expect(client.device_name).to eq('iPhone 5S')
79
+ end
80
+
81
+ end
82
+
83
+ describe '#device_type' do
84
+
85
+ it 'returns the device type' do
86
+ expect(client.device_type).to eq('smartphone')
87
+ end
60
88
 
61
- it 'returns nil' do
62
- expect(client.bot_name).to be_nil
63
89
  end
64
90
 
65
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: device_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mati Sójka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-18 00:00:00.000000000 Z
12
+ date: 2015-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -62,7 +62,10 @@ files:
62
62
  - lib/device_detector.rb
63
63
  - lib/device_detector/bot.rb
64
64
  - lib/device_detector/client.rb
65
+ - lib/device_detector/device.rb
65
66
  - lib/device_detector/memory_cache.rb
67
+ - lib/device_detector/metadata_extractor.rb
68
+ - lib/device_detector/model_extractor.rb
66
69
  - lib/device_detector/os.rb
67
70
  - lib/device_detector/parser.rb
68
71
  - lib/device_detector/version.rb
@@ -70,13 +73,16 @@ files:
70
73
  - regexes/bots.yml
71
74
  - regexes/browser_engines.yml
72
75
  - regexes/browsers.yml
76
+ - regexes/devices/mobiles.yml
73
77
  - regexes/feed_readers.yml
74
78
  - regexes/libraries.yml
75
79
  - regexes/mediaplayers.yml
76
80
  - regexes/mobile_apps.yml
77
81
  - regexes/oss.yml
78
82
  - regexes/pim.yml
83
+ - spec/device_detector/device_spec.rb
79
84
  - spec/device_detector/memory_cache_spec.rb
85
+ - spec/device_detector/model_extractor_spec.rb
80
86
  - spec/device_detector/version_extractor_spec.rb
81
87
  - spec/device_detector_spec.rb
82
88
  - spec/spec_helper.rb
@@ -100,12 +106,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
106
  version: '0'
101
107
  requirements: []
102
108
  rubyforge_project:
103
- rubygems_version: 2.2.2
109
+ rubygems_version: 2.4.5
104
110
  signing_key:
105
111
  specification_version: 4
106
112
  summary: Universal Device Detection
107
113
  test_files:
114
+ - spec/device_detector/device_spec.rb
108
115
  - spec/device_detector/memory_cache_spec.rb
116
+ - spec/device_detector/model_extractor_spec.rb
109
117
  - spec/device_detector/version_extractor_spec.rb
110
118
  - spec/device_detector_spec.rb
111
119
  - spec/spec_helper.rb