rack-ketai 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/ketai/carrier/abstract.rb +11 -0
- data/lib/rack/ketai/carrier/android.rb +9 -0
- data/lib/rack/ketai/carrier/cidrs/au.rb +1 -12
- data/lib/rack/ketai/carrier/cidrs/docomo.rb +1 -1
- data/lib/rack/ketai/carrier/cidrs/softbank.rb +6 -4
- data/lib/rack/ketai/carrier/iphone.rb +9 -1
- data/lib/rack/ketai/carrier/mobile.rb +4 -0
- data/lib/rack/ketai/carrier/smartphone.rb +1 -1
- metadata +69 -81
- data/VERSION +0 -1
- data/rack-ketai.gemspec +0 -91
- data/spec/spec_helper.rb +0 -11
- data/spec/unit/android_spec.rb +0 -50
- data/spec/unit/au_filter_spec.rb +0 -105
- data/spec/unit/au_spec.rb +0 -248
- data/spec/unit/carrier_spec.rb +0 -30
- data/spec/unit/display_spec.rb +0 -25
- data/spec/unit/docomo_filter_spec.rb +0 -115
- data/spec/unit/docomo_spec.rb +0 -351
- data/spec/unit/emoticon_filter_spec.rb +0 -108
- data/spec/unit/filter_spec.rb +0 -38
- data/spec/unit/general_spec.rb +0 -41
- data/spec/unit/gps_spec.rb +0 -146
- data/spec/unit/iphone_spec.rb +0 -95
- data/spec/unit/middleware_spec.rb +0 -38
- data/spec/unit/position_spec.rb +0 -49
- data/spec/unit/softbank_filter_spec.rb +0 -142
- data/spec/unit/softbank_spec.rb +0 -207
- data/spec/unit/valid_addr_spec.rb +0 -116
- data/test/spec_runner.rb +0 -30
- data/tools/generate_emoji_dic.rb +0 -430
- data/tools/update_speclist.rb +0 -87
data/spec/unit/android_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'rack/ketai/carrier/android'
|
3
|
-
describe "Rack::Ketai::Carrier::Android" do
|
4
|
-
|
5
|
-
describe 'Android 2.1 でのアクセスのとき' do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
9
|
-
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.1-update1; ja-jp; SonyEricssonSO-01B Build/2.0.B.0.138) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17',
|
10
|
-
'REMOTE_ADDR' => '110.160.154.44')
|
11
|
-
@mobile = Rack::Ketai::Carrier.load(@env)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'PC向け絵文字フィルタが適用されること' do
|
15
|
-
mock_app = mock('App')
|
16
|
-
mock_app.should_receive(:call).twice do |env|
|
17
|
-
[200, { "Content-Type" => "text/html"}, ["今日は良い天気ですね[e:000]"]]
|
18
|
-
end
|
19
|
-
|
20
|
-
middleware = Rack::Ketai::Middleware.new(mock_app, {})
|
21
|
-
middleware.call(@env)[2].should == ['今日は良い天気ですね[e:000]']
|
22
|
-
|
23
|
-
middleware = Rack::Ketai::Middleware.new(mock_app, { :emoticons_path => '/path-to/emoticons' })
|
24
|
-
middleware.call(@env)[2].should == ['今日は良い天気ですね<img src="/path-to/emoticons/sun.gif" />']
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'Rack::Ketai::Carrier::Android がセットされること' do
|
28
|
-
@mobile.should be_is_a(Rack::Ketai::Carrier::Android)
|
29
|
-
end
|
30
|
-
|
31
|
-
it '携帯端末であること' do
|
32
|
-
@mobile.should be_mobile
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'スマートフォンであること' do
|
36
|
-
@mobile.should be_smartphone
|
37
|
-
end
|
38
|
-
|
39
|
-
it "#supports_cookie? は true を返すこと" do
|
40
|
-
@mobile.should be_respond_to(:supports_cookie?)
|
41
|
-
@mobile.should be_supports_cookie
|
42
|
-
end
|
43
|
-
|
44
|
-
it "#valid_addr? は false を返すこと" do
|
45
|
-
@mobile.should_not be_valid_addr
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
data/spec/unit/au_filter_spec.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'kconv'
|
3
|
-
require 'rack/ketai/carrier/au'
|
4
|
-
describe Rack::Ketai::Carrier::Au::Filter, "内部エンコーディングに変換する時" do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@filter = Rack::Ketai::Carrier::Au::Filter.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "POSTデータ中のSJISバイナリの絵文字を絵文字IDに変換すること" do
|
11
|
-
Rack::Ketai::Carrier::Au::Filter::EMOJI_TO_EMOJIID.should_not be_empty
|
12
|
-
Rack::Ketai::Carrier::Au::Filter::EMOJI_TO_EMOJIID.each do |emoji, emojiid|
|
13
|
-
postdata = "message=" + CGI.escape("今日はいい".tosjis + emoji + "ですね。".tosjis)
|
14
|
-
postdata.force_encoding('Shift_JIS') if postdata.respond_to?(:force_encoding)
|
15
|
-
|
16
|
-
env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
17
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
18
|
-
:method => 'POST',
|
19
|
-
:input => postdata)
|
20
|
-
env = @filter.inbound(env)
|
21
|
-
request = Rack::Request.new(env)
|
22
|
-
request.params['message'].should == '今日はいい[e:'+format("%03X", emojiid)+']ですね。'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Rack::Ketai::Carrier::Au::Filter, "外部エンコーディングに変換する時" do
|
29
|
-
|
30
|
-
before(:each) do
|
31
|
-
@filter = Rack::Ketai::Carrier::Au::Filter.new
|
32
|
-
end
|
33
|
-
|
34
|
-
# Rails 3.0.0+Ruby1.9.xのとき、bodyにeachの使えないStringが渡されてエラーになったので
|
35
|
-
it "bodyにStringを受け取ってもよきにはからってくれること" do
|
36
|
-
status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, 'String')
|
37
|
-
body.should == ['String']
|
38
|
-
end
|
39
|
-
|
40
|
-
it "データ中の絵文字IDをSJISの絵文字コードに変換すること" do
|
41
|
-
Rack::Ketai::Carrier::Au::Filter::EMOJI_TO_EMOJIID.should_not be_empty
|
42
|
-
Rack::Ketai::Carrier::Au::Filter::EMOJI_TO_EMOJIID.each do |emoji, emojiid|
|
43
|
-
resdata = "今日はいい".tosjis + emoji + "ですね。".tosjis
|
44
|
-
|
45
|
-
status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ['今日はいい[e:'+format("%03X", emojiid)+']ですね。'])
|
46
|
-
|
47
|
-
body[0].should == resdata
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "Content-typeが指定なし,text/html, application/xhtml+xml 以外の時はフィルタを適用しないこと" do
|
52
|
-
Rack::Ketai::Carrier::Au::Filter::EMOJI_TO_EMOJIID.should_not be_empty
|
53
|
-
Rack::Ketai::Carrier::Au::Filter::EMOJI_TO_EMOJIID.each do |emoji, emojiid|
|
54
|
-
internaldata = '今日はいい[e:'+format("%03X", emojiid)+']ですね。'
|
55
|
-
%w(text/plain text/xml text/json application/json text/javascript application/rss+xml image/jpeg).each do |contenttype|
|
56
|
-
status, headers, body = @filter.outbound(200, { "Content-Type" => contenttype }, [internaldata])
|
57
|
-
body[0].should == internaldata
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "データ中に絵文字ID=絵文字IDだが絵文字!=絵文字IDのIDが含まれているとき、正しく逆変換できること" do
|
63
|
-
emoji = [0xF649].pack('n')
|
64
|
-
emoji.force_encoding('Shift_JIS') if emoji.respond_to?(:force_encoding)
|
65
|
-
resdata = "たとえば".tosjis+emoji+"「e-338 HAPPY FACE WITH OPEN MOUTH AND RAISED EYEBROWS」とか。".tosjis
|
66
|
-
|
67
|
-
status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ["たとえば[e:338]「e-338 HAPPY FACE WITH OPEN MOUTH AND RAISED EYEBROWS」とか。"])
|
68
|
-
|
69
|
-
body[0].should == resdata
|
70
|
-
end
|
71
|
-
|
72
|
-
it "データ中にauにはない絵文字IDが存在するとき、代替文字を表示すること" do
|
73
|
-
resdata = "Soon[SOON]です".tosjis # soon
|
74
|
-
|
75
|
-
status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ['Soon[e:018]です'])
|
76
|
-
|
77
|
-
body[0].should == resdata
|
78
|
-
end
|
79
|
-
|
80
|
-
it "Content-typeを適切に書き換えられること" do
|
81
|
-
[
|
82
|
-
[nil, nil],
|
83
|
-
['text/html', 'text/html; charset=shift_jis'],
|
84
|
-
['text/html; charset=utf-8', 'text/html; charset=shift_jis'],
|
85
|
-
['text/html;charset=utf-8', 'text/html;charset=shift_jis'],
|
86
|
-
['application/xhtml+xml', 'application/xhtml+xml; charset=shift_jis'],
|
87
|
-
['application/xhtml+xml; charset=utf-8', 'application/xhtml+xml; charset=shift_jis'],
|
88
|
-
['application/xhtml+xml;charset=utf-8', 'application/xhtml+xml;charset=shift_jis'],
|
89
|
-
['text/javascript', 'text/javascript'],
|
90
|
-
['text/json', 'text/json'],
|
91
|
-
['application/json', 'application/json'],
|
92
|
-
['text/javascript+json', 'text/javascript+json'],
|
93
|
-
['image/jpeg', 'image/jpeg'],
|
94
|
-
['application/octet-stream', 'application/octet-stream'],
|
95
|
-
].each do |content_type, valid_content_type|
|
96
|
-
orig_content_type = content_type == nil ? nil : content_type.clone
|
97
|
-
status, headers, body = @filter.outbound(200, { "Content-Type" => content_type}, ['適当な本文'])
|
98
|
-
headers['Content-Type'].should == valid_content_type
|
99
|
-
# 元の文字列に直接変更を加えない(Rails3.0でハッシュを使い回してるようだったので)
|
100
|
-
content_type.should == orig_content_type
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
data/spec/unit/au_spec.rb
DELETED
@@ -1,248 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'rack/ketai/carrier/au'
|
3
|
-
describe "Rack::Ketai::Carrier::Au" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "WAP2.0ブラウザ搭載端末で" do
|
10
|
-
|
11
|
-
# http://ke-tai.org/blog/2008/09/08/phoneid/
|
12
|
-
# http://www.au.kddi.com/ezfactory/tec/spec/4_4.html
|
13
|
-
|
14
|
-
describe "EZ番号(サブスクライバID)を取得できたとき" do
|
15
|
-
|
16
|
-
before(:each) do
|
17
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
18
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
19
|
-
'HTTP_X_UP_SUBNO' => '01234567890123_xx.ezweb.ne.jp')
|
20
|
-
@mobile = Rack::Ketai::Carrier::Au.new(@env)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "#subscriberid でEZ番号を取得できること" do
|
24
|
-
@mobile.subscriberid.should == '01234567890123_xx.ezweb.ne.jp'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "#deviceid は nil なこと" do
|
28
|
-
@mobile.deviceid.should be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "#ident でEZ番号を取得できること" do
|
32
|
-
@mobile.ident.should == @mobile.subscriberid
|
33
|
-
@mobile.ident.should == '01234567890123_xx.ezweb.ne.jp'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "#name で機種名を取得できること" do
|
37
|
-
@mobile.name.should == 'SA31'
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'スマートフォンではないこと' do
|
43
|
-
env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
44
|
-
'HTTP_USER_AGENT' => 'KDDI-HI3B UP.Browser/6.2.0.13.2 (GUI) MMP/2.0',
|
45
|
-
'HTTP_X_UP_DEVCAP_MAX_PDU' => '131072')
|
46
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
47
|
-
mobile.should_not be_smartphone
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#cache_size でキャッシュ容量を取得するとき" do
|
51
|
-
|
52
|
-
it "環境変数を使用すること" do
|
53
|
-
env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
54
|
-
'HTTP_USER_AGENT' => 'KDDI-HI3B UP.Browser/6.2.0.13.2 (GUI) MMP/2.0',
|
55
|
-
'HTTP_X_UP_DEVCAP_MAX_PDU' => '131072')
|
56
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
57
|
-
mobile.cache_size.should == 131072
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
it "環境変数で取得できない古い機種のときは8220Byteにしとく(適当)" do
|
62
|
-
env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
63
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-SYT4 UP.Link/3.4.5.6')
|
64
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
65
|
-
mobile.cache_size.should == 8220
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "ディスプレイ情報を取得するとき" do
|
71
|
-
|
72
|
-
describe "既知の端末のとき" do
|
73
|
-
|
74
|
-
it "環境変数を優先すること" do
|
75
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
76
|
-
'HTTP_USER_AGENT' => 'KDDI-TS31 UP.Browser/6.2.0.8 (GUI) MMP/2.0',
|
77
|
-
'HTTP_X_UP_DEVCAP_SCREENPIXELS' => '1024,768',
|
78
|
-
'HTTP_X_UP_DEVCAP_SCREENDEPTH' => '8')
|
79
|
-
@mobile = Rack::Ketai::Carrier::Au.new(@env)
|
80
|
-
display = @mobile.display
|
81
|
-
display.should_not be_nil
|
82
|
-
display.colors.should == 256
|
83
|
-
display.width.should == 1024
|
84
|
-
display.height.should == 768
|
85
|
-
|
86
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
87
|
-
'HTTP_USER_AGENT' => 'KDDI-TS31 UP.Browser/6.2.0.8 (GUI) MMP/2.0')
|
88
|
-
@mobile = Rack::Ketai::Carrier::Au.new(@env)
|
89
|
-
display = @mobile.display
|
90
|
-
display.should_not be_nil
|
91
|
-
display.colors.should == 65536
|
92
|
-
display.width.should == 229
|
93
|
-
display.height.should == 270
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "未知の端末のとき" do
|
99
|
-
|
100
|
-
it "環境変数から設定すること" do
|
101
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
102
|
-
'HTTP_USER_AGENT' => 'KDDI-XX01 UP.Browser/6.2.0.8 (GUI) MMP/2.0',
|
103
|
-
'HTTP_X_UP_DEVCAP_SCREENPIXELS' => '1024,768',
|
104
|
-
'HTTP_X_UP_DEVCAP_SCREENDEPTH' => '8')
|
105
|
-
@mobile = Rack::Ketai::Carrier::Au.new(@env)
|
106
|
-
display = @mobile.display
|
107
|
-
display.should_not be_nil
|
108
|
-
display.colors.should == 256
|
109
|
-
display.width.should == 1024
|
110
|
-
display.height.should == 768
|
111
|
-
end
|
112
|
-
|
113
|
-
it "環境変数が無かったら慌てず騒がず nil を返す" do
|
114
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
115
|
-
'HTTP_USER_AGENT' => 'KDDI-XX01 UP.Browser/6.2.0.8 (GUI) MMP/2.0')
|
116
|
-
@mobile = Rack::Ketai::Carrier::Au.new(@env)
|
117
|
-
display = @mobile.display
|
118
|
-
display.should_not be_nil
|
119
|
-
display.colors.should be_nil
|
120
|
-
display.width.should be_nil
|
121
|
-
display.height.should be_nil
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "EZ番号が取得できないとき" do
|
129
|
-
|
130
|
-
before(:each) do
|
131
|
-
@env = Rack::MockRequest.env_for('http://hoge.com/dummy',
|
132
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
|
133
|
-
@mobile = Rack::Ketai::Carrier::Au.new(@env)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "#subscriberid は nil を返すこと" do
|
137
|
-
@mobile.subscriberid.should be_nil
|
138
|
-
end
|
139
|
-
|
140
|
-
it "#deviceid は nil を返すこと" do
|
141
|
-
@mobile.deviceid.should be_nil
|
142
|
-
end
|
143
|
-
|
144
|
-
it "#ident は nil を返すこと" do
|
145
|
-
@mobile.ident.should be_nil
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "#supports_cookie? を使うとき" do
|
152
|
-
|
153
|
-
# Au のCookie対応状況
|
154
|
-
# 全機種対応(GW側で保持)
|
155
|
-
# SSL接続時はWAP2.0ブラウザ搭載端末でのみ端末に保持したCookieを送出
|
156
|
-
# http://www.au.kddi.com/ezfactory/tec/spec/cookie.html
|
157
|
-
|
158
|
-
it "WAP1.0端末(HTTP)のとき true を返すこと" do
|
159
|
-
{
|
160
|
-
'http://hoge.com/dummy' => {
|
161
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-KCTE UP.Link/3.4.5.9'
|
162
|
-
},
|
163
|
-
'http://hoge.com/dummy' => {
|
164
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-KCTE UP.Link/3.4.5.9',
|
165
|
-
'HTTPS' => 'OFF'
|
166
|
-
},
|
167
|
-
'http://hoge.com/dummy' => {
|
168
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-KCTE UP.Link/3.4.5.9',
|
169
|
-
'X_FORWARDED_PROTO' => 'http'
|
170
|
-
}
|
171
|
-
}.each do |url, opt|
|
172
|
-
env = Rack::MockRequest.env_for(url, opt)
|
173
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
174
|
-
mobile.should be_respond_to(:supports_cookie?)
|
175
|
-
mobile.should be_supports_cookie
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
it "WAP1.0端末(HTTPS)のとき false を返すこと" do
|
181
|
-
{
|
182
|
-
'https://hoge.com/dummy' => {
|
183
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-KCTE UP.Link/3.4.5.9',
|
184
|
-
'HTTPS' => 'on'
|
185
|
-
},
|
186
|
-
'https://hoge.com/dummy' => {
|
187
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-KCTE UP.Link/3.4.5.9',
|
188
|
-
'HTTPS' => 'ON'
|
189
|
-
},
|
190
|
-
'http://hoge.com/dummy' => {
|
191
|
-
'HTTP_USER_AGENT' => 'UP.Browser/3.04-KCTE UP.Link/3.4.5.9',
|
192
|
-
'X_FORWARDED_PROTO' => 'https' # RAILS的 リバースプロキシのバックエンドでHTTPSを判断する方法
|
193
|
-
}
|
194
|
-
}.each do |url, opt|
|
195
|
-
env = Rack::MockRequest.env_for(url, opt)
|
196
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
197
|
-
mobile.should be_respond_to(:supports_cookie?)
|
198
|
-
mobile.should_not be_supports_cookie
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
it "WAP2.0端末(HTTP)のとき true を返すこと" do
|
203
|
-
{
|
204
|
-
'http://hoge.com/dummy' => {
|
205
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0'
|
206
|
-
},
|
207
|
-
'http://hoge.com/dummy' => {
|
208
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
209
|
-
'HTTPS' => 'OFF'
|
210
|
-
},
|
211
|
-
'http://hoge.com/dummy' => {
|
212
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
213
|
-
'X_FORWARDED_PROTO' => 'http'
|
214
|
-
}
|
215
|
-
}.each do |url, opt|
|
216
|
-
env = Rack::MockRequest.env_for(url, opt)
|
217
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
218
|
-
mobile.should be_respond_to(:supports_cookie?)
|
219
|
-
mobile.should be_supports_cookie
|
220
|
-
end
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
it "WAP2.0端末(HTTPS)のとき true を返すこと" do
|
225
|
-
{
|
226
|
-
'https://hoge.com/dummy' => {
|
227
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
228
|
-
'HTTPS' => 'on'
|
229
|
-
},
|
230
|
-
'https://hoge.com/dummy' => {
|
231
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
232
|
-
'HTTPS' => 'ON'
|
233
|
-
},
|
234
|
-
'http://hoge.com/dummy' => {
|
235
|
-
'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0',
|
236
|
-
'X_FORWARDED_PROTO' => 'https' # RAILS的 リバースプロキシのバックエンドでHTTPSを判断する方法
|
237
|
-
}
|
238
|
-
}.each do |url, opt|
|
239
|
-
env = Rack::MockRequest.env_for(url, opt)
|
240
|
-
mobile = Rack::Ketai::Carrier::Au.new(env)
|
241
|
-
mobile.should be_respond_to(:supports_cookie?)
|
242
|
-
mobile.should be_supports_cookie
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
end
|
data/spec/unit/carrier_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
describe Rack::Ketai::Carrier, "#load を実行するとき" do
|
4
|
-
|
5
|
-
it "適切なキャリアを設定できること" do
|
6
|
-
{
|
7
|
-
'DoCoMo/1.0/N505i' => Rack::Ketai::Carrier::Docomo, # Mova
|
8
|
-
'DoCoMo/2.0 P903i' => Rack::Ketai::Carrier::Docomo, # FOMA
|
9
|
-
'KDDI-CA39 UP.Browser/6.2.0.13.1.5 (GUI) MMP/2.0' => Rack::Ketai::Carrier::Au, # WAP2.0 MMP2.0
|
10
|
-
'KDDI-TS21 UP.Browser/6.0.2.273 (GUI) MMP/1.1' => Rack::Ketai::Carrier::Au, # WAP2.0 MMP1.1
|
11
|
-
'SoftBank/1.0/930SH/SHJ001[/Serial] Browser/NetFront/3.4 Profile/MIDP-2.0 Configuration/CLDC-1.1' => Rack::Ketai::Carrier::Softbank, # SoftBank 3GC
|
12
|
-
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_0_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5B108 Safari/525.20' => Rack::Ketai::Carrier::IPhone,
|
13
|
-
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Q312461; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727)' => nil, # IE8
|
14
|
-
'Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1' => nil,
|
15
|
-
'Opera/9.21 (Windows NT 5.1; U; ja)' => nil,
|
16
|
-
'Mozilla/5.0 (Windows; U; Windows NT 5.1; ja-JP) AppleWebKit/525.19 (KHTML, like Gecko) Version/3.1.2 Safari/525.21' => nil,
|
17
|
-
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13' => nil,
|
18
|
-
}.each do |ua, carrier|
|
19
|
-
env = Rack::MockRequest.env_for('http://hoge.com/dummy','HTTP_USER_AGENT' => ua)
|
20
|
-
obj = Rack::Ketai::Carrier.load(env)
|
21
|
-
if carrier
|
22
|
-
obj.should be_is_a(carrier)
|
23
|
-
obj.should be_mobile
|
24
|
-
else
|
25
|
-
obj.should_not be_mobile
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/spec/unit/display_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'rack/ketai/display'
|
3
|
-
describe "Rack::Ketai::Display" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@display1 = Rack::Ketai::Display.new
|
7
|
-
@display2 = Rack::Ketai::Display.new(:colors => 256, :width => 240, :height => 360)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "#colors で色数を取得可能なこと、未設定ならnil" do
|
11
|
-
@display1.colors.should be_nil
|
12
|
-
@display2.colors.should == 256
|
13
|
-
end
|
14
|
-
|
15
|
-
it "#width でブラウザ横幅を取得可能なこと、未設定ならnil" do
|
16
|
-
@display1.width.should be_nil
|
17
|
-
@display2.width.should == 240
|
18
|
-
end
|
19
|
-
|
20
|
-
it "#height でブラウザ縦幅を取得可能なこと、未設定ならnil" do
|
21
|
-
@display1.height.should be_nil
|
22
|
-
@display2.height.should == 360
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|