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.
@@ -1,115 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'kconv'
3
- require 'rack/ketai/carrier/docomo'
4
- describe Rack::Ketai::Carrier::Docomo::Filter, "内部エンコーディングに変換する時" do
5
-
6
- before(:each) do
7
- @filter = Rack::Ketai::Carrier::Docomo::Filter.new
8
- end
9
-
10
- it "POSTデータ中のSJISバイナリの絵文字を絵文字IDに変換すること" do
11
- Rack::Ketai::Carrier::Docomo::Filter::EMOJI_TO_EMOJIID.should_not be_empty
12
- Rack::Ketai::Carrier::Docomo::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' => 'DoCoMo/2.0 P903i',
18
- :method => 'POST', # rack 1.1.0 以降ではこれがないとパーサが動かない
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::Docomo::Filter, "外部エンコーディングに変換する時" do
29
-
30
- before(:each) do
31
- @filter = Rack::Ketai::Carrier::Docomo::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::Docomo::Filter::EMOJI_TO_EMOJIID.should_not be_empty
42
- Rack::Ketai::Carrier::Docomo::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
-
50
- # 複数の絵文字IDに割り当てられている絵文字
51
- hotel = [0xF8CA].pack('n*')
52
- harts = [0xF994].pack('n*')
53
- [hotel, harts].each{ |e| e.force_encoding('Shift_JIS') if e.respond_to?(:force_encoding) }
54
- resdata = "ラブホテル".tosjis + hotel + harts
55
- status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ['ラブホテル[e:4B8]'])
56
-
57
- body[0].should == resdata
58
-
59
- end
60
-
61
- it "Content-typeが指定なし,text/html, application/xhtml+xml 以外の時はフィルタを適用しないこと" do
62
- Rack::Ketai::Carrier::Docomo::Filter::EMOJI_TO_EMOJIID.should_not be_empty
63
- Rack::Ketai::Carrier::Docomo::Filter::EMOJI_TO_EMOJIID.each do |emoji, emojiid|
64
- internaldata = '今日はいい[e:'+format("%03X", emojiid)+']ですね。'
65
- %w(text/plain text/xml text/json application/json text/javascript application/rss+xml image/jpeg application/x-shockwave-flash).each do |contenttype|
66
- status, headers, body = @filter.outbound(200, { "Content-Type" => contenttype }, [internaldata])
67
- body[0].should == internaldata
68
- end
69
- end
70
- end
71
-
72
- it "データ中に絵文字ID=絵文字IDだが絵文字!=絵文字IDのIDが含まれているとき、正しく逆変換できること" do
73
- emoji = [0xF995].pack('n')
74
- emoji.force_encoding('Shift_JIS') if emoji.respond_to?(:force_encoding)
75
- resdata = "たとえば".tosjis+emoji+"「e-330 HAPPY FACE WITH OPEN MOUTH」とか。".tosjis
76
-
77
- status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ["たとえば[e:330]「e-330 HAPPY FACE WITH OPEN MOUTH」とか。"])
78
-
79
- body[0].should == resdata
80
- end
81
-
82
- it "データ中にドコモにはない絵文字IDが存在するとき、代替文字を表示すること" do
83
- resdata = "黒い矢印[#{[0x2190].pack('U')}]です".tosjis # 左黒矢印
84
-
85
- status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ['黒い矢印[e:AFB]です'])
86
-
87
- body[0].should == resdata
88
- end
89
-
90
- it "Content-typeを適切に書き換えられること" do
91
- [
92
- [nil, nil],
93
- ['text/html', 'application/xhtml+xml; charset=shift_jis'],
94
- ['text/html; charset=utf-8', 'application/xhtml+xml; charset=shift_jis'],
95
- ['text/html;charset=utf-8', 'application/xhtml+xml;charset=shift_jis'],
96
- ['application/xhtml+xml', 'application/xhtml+xml; charset=shift_jis'],
97
- ['application/xhtml+xml; charset=utf-8', 'application/xhtml+xml; charset=shift_jis'],
98
- ['application/xhtml+xml;charset=utf-8', 'application/xhtml+xml;charset=shift_jis'],
99
- ['text/javascript', 'text/javascript'],
100
- ['text/json', 'text/json'],
101
- ['application/json', 'application/json'],
102
- ['text/javascript+json', 'text/javascript+json'],
103
- ['image/jpeg', 'image/jpeg'],
104
- ['application/octet-stream', 'application/octet-stream'],
105
- ].each do |content_type, valid_content_type|
106
- orig_content_type = content_type == nil ? nil : content_type.clone
107
- status, headers, body = @filter.outbound(200, { "Content-Type" => content_type}, ['適当な本文'])
108
- headers['Content-Type'].should == valid_content_type
109
- # 元の文字列に直接変更を加えない(Rails3.0でハッシュを使い回してるようだったので)
110
- content_type.should == orig_content_type
111
- end
112
- end
113
-
114
- end
115
-
@@ -1,351 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rack/ketai/carrier/docomo'
3
- describe "Rack::Ketai::Carrier::Docomo" do
4
-
5
- # UAの意味
6
- # http://www.nttdocomo.co.jp/service/imode/make/content/browser/html/useragent/
7
-
8
- before(:each) do
9
-
10
- end
11
-
12
- describe "FOMA端末で" do
13
-
14
- # http://www.nttdocomo.co.jp/service/imode/make/content/browser/html/tag/utn.html
15
- # FOMA端末製造番号のみ、もしくはFOMAカード製造番号のみの送信はできません。
16
-
17
- describe "iモードIDを取得できたとき" do
18
- before(:each) do
19
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy?guid=ON',
20
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 P903i(c10;serXXXXXXXXXXXXXXX; iccxxxxxxxxxxxxxxxxxxxx)',
21
- 'HTTP_X_DCMGUID' => '0123abC')
22
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
23
- end
24
-
25
- it "#subscriberid でiモードIDを取得できること" do
26
- @mobile.subscriberid.should == '0123abC'
27
- end
28
-
29
- it "#deviceid でFOMA端末個体識別子を取得できること" do
30
- @mobile.deviceid.should == "XXXXXXXXXXXXXXX"
31
- end
32
-
33
- it "#ident でiモードIDを取得できること" do
34
- @mobile.ident.should == @mobile.subscriberid
35
- @mobile.ident.should == '0123abC'
36
- end
37
-
38
- end
39
-
40
- describe "iモードIDが取得できず、FOMAカード個体識別子、FOMA端末個体識別子双方を取得できたとき" do
41
-
42
- before(:each) do
43
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
44
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 P903i(c10;serXXXXXXXXXXXXXXX; iccxxxxxxxxxxxxxxxxxxxx)')
45
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
46
- end
47
-
48
- it "#subscriberid でFOMAカード個体識別子を取得できること" do
49
- @mobile.subscriberid.should == "xxxxxxxxxxxxxxxxxxxx"
50
- end
51
-
52
- it "#deviceid でFOMA端末個体識別子を取得できること" do
53
- @mobile.deviceid.should == "XXXXXXXXXXXXXXX"
54
- end
55
-
56
- it "#ident でFOMAカード個体識別子を取得できること" do
57
- @mobile.ident.should == @mobile.subscriberid
58
- @mobile.ident.should == "xxxxxxxxxxxxxxxxxxxx"
59
- end
60
- end
61
-
62
- describe "iモードID、FOMAカード個体識別子およびFOMA端末個体識別子が取得できないとき" do
63
-
64
- before(:each) do
65
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
66
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 SO903i')
67
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
68
- end
69
-
70
- it "#subscriberid は nil を返すこと" do
71
- @mobile.subscriberid.should be_nil
72
- end
73
-
74
- it "#deviceid は nil を返すこと" do
75
- @mobile.deviceid.should be_nil
76
- end
77
-
78
- it "#ident は nil を返すこと" do
79
- @mobile.ident.should be_nil
80
- end
81
- end
82
-
83
- describe "iモードIDが取得でき、FOMAカード個体識別子およびFOMA端末個体識別子が取得できないとき" do
84
-
85
- before(:each) do
86
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
87
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 SO903i',
88
- 'HTTP_X_DCMGUID' => '0123abC')
89
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
90
- end
91
-
92
- it "#subscriberid はiモードIDを返すこと" do
93
- @mobile.subscriberid.should == '0123abC'
94
- end
95
-
96
- it "#deviceid は nil を返すこと" do
97
- @mobile.deviceid.should be_nil
98
- end
99
-
100
- it "#ident はiモードIDを返すこと" do
101
- @mobile.ident.should == '0123abC'
102
- end
103
- end
104
-
105
- it "#name で機種名を取得できること" do
106
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
107
- 'HTTP_USER_AGENT' => "DoCoMo/2.0 SH02A")
108
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
109
- mobile.name.should == 'SH02A'
110
- end
111
-
112
- it "#cache_size でキャッシュサイズが取得できること" do
113
- {
114
- 'DoCoMo/2.0 P903i' => 5 * 1000,
115
- 'DoCoMo/2.0 F900i(c100;TJ)' => 100 * 1000,
116
- 'DoCoMo/2.0 F900i(c100;TC;W22H12)' => 100 * 1000,
117
- 'DoCoMo/2.0 P903i(c100;serXXXXXXXXXXXXXXX; iccxxxxxxxxxxxxxxxxxxxx)' => 100 * 1000,
118
- 'DoCoMo/2.0 N06A3(c500;TB;W24H16)' => 500 * 1000,
119
- 'DoCoMo/2.0 XXXX(c500;TB;W24H16)' => 500 * 1000 # 未知の端末でも
120
- }.each do |ua, cache_size|
121
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
122
- 'HTTP_USER_AGENT' => ua)
123
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
124
- mobile.cache_size.should == cache_size
125
- end
126
- end
127
-
128
- it 'スマートフォンではないこと' do
129
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
130
- 'HTTP_USER_AGENT' => "DoCoMo/2.0 SH02A")
131
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
132
- mobile.should_not be_smartphone
133
- end
134
-
135
- describe "ディスプレイ情報を取得できること" do
136
-
137
- it "既知の端末のとき" do
138
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
139
- 'HTTP_USER_AGENT' => "DoCoMo/2.0 SH02A(c100;TB;W30H20)")
140
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
141
- display = @mobile.display
142
- display.should_not be_nil
143
- display.colors.should == 16777216
144
- display.width.should == 240
145
- display.height.should == 320
146
- end
147
-
148
- it "未知の端末のとき" do
149
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
150
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 XX01(c100;TB;W30H20)')
151
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
152
- display = @mobile.display
153
- display.should_not be_nil
154
- display.colors.should be_nil
155
- display.width.should be_nil
156
- display.height.should be_nil
157
- end
158
-
159
- end
160
-
161
- end
162
-
163
- describe "mova端末で" do
164
-
165
- # http://www.nttdocomo.co.jp/service/imode/make/content/browser/html/tag/utn.html
166
-
167
- describe "iモードIDと端末個体識別子を取得できたとき" do
168
- before(:each) do
169
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy?guid=ON',
170
- 'HTTP_USER_AGENT' => 'DoCoMo/1.0/SO503i/c10/TB/serXXXXXXXXXXX',
171
- 'HTTP_X_DCMGUID' => '0123abC')
172
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
173
- end
174
-
175
- it "#subscriberid でiモードIDを取得できること" do
176
- @mobile.subscriberid.should == '0123abC'
177
- end
178
-
179
- it "#deviceid で端末個体識別子を取得できること" do
180
- @mobile.deviceid.should == "XXXXXXXXXXX"
181
- end
182
-
183
- it "#ident でiモードIDを取得できること" do
184
- @mobile.ident.should == '0123abC'
185
- end
186
-
187
- end
188
-
189
- describe "端末個体識別子のみ取得できたとき" do
190
-
191
- before(:each) do
192
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
193
- 'HTTP_USER_AGENT' => 'DoCoMo/1.0/SO503i/c10/TB/serXXXXXXXXXXX')
194
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
195
- end
196
-
197
- it "#subscriberid は nil を返すこと" do
198
- @mobile.subscriberid.should be_nil
199
- end
200
-
201
- it "#deviceid で端末個体識別子を取得できること" do
202
- @mobile.deviceid.should == "XXXXXXXXXXX"
203
- end
204
-
205
- it "#ident で端末個体識別子を取得できること" do
206
- @mobile.ident.should == @mobile.deviceid
207
- @mobile.ident.should == "XXXXXXXXXXX"
208
- end
209
- end
210
-
211
- describe "iモードIDも端末個体識別子も取得できないとき" do
212
-
213
- before(:each) do
214
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
215
- 'HTTP_USER_AGENT' => 'DoCoMo/1.0/N505i/c20/TB/W24H12')
216
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
217
- end
218
-
219
- it "#subscriberid は nil を返すこと" do
220
- @mobile.subscriberid.should be_nil
221
- end
222
-
223
- it "#deviceid は nil を返すこと" do
224
- @mobile.deviceid.should be_nil
225
- end
226
-
227
- it "#ident は nil を返すこと" do
228
- @mobile.ident.should be_nil
229
- end
230
- end
231
-
232
- describe "iモードIDのみ取得できたとき" do
233
-
234
- before(:each) do
235
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
236
- 'HTTP_USER_AGENT' => 'DoCoMo/1.0/N505i/c20/TB/W24H12',
237
- 'HTTP_X_DCMGUID' => '0123abC')
238
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
239
- end
240
-
241
- it "#subscriberid はiモードIDを返すこと" do
242
- @mobile.subscriberid.should == '0123abC'
243
- end
244
-
245
- it "#deviceid は nil を返すこと" do
246
- @mobile.deviceid.should be_nil
247
- end
248
-
249
- it "#ident はiモードIDを返すこと" do
250
- @mobile.ident.should == '0123abC'
251
- end
252
- end
253
-
254
- it "#name で機種名を取得できること" do
255
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
256
- 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO502i")
257
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
258
- mobile.name.should == 'SO502i'
259
- end
260
-
261
- it "#cache_size でキャッシュサイズが取得できること" do
262
- {
263
- 'DoCoMo/1.0/F502i' => 5 * 1000,
264
- 'DoCoMo/1.0/D503i/c10' => 10 * 1000,
265
- 'DoCoMo/1.0/N504i/c10/TB' => 10 * 1000,
266
- 'DoCoMo/1.0/SO506iS/c20/TB/W20H10' => 20 * 1000,
267
- }.each do |ua, cache_size|
268
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
269
- 'HTTP_USER_AGENT' => ua)
270
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
271
- mobile.cache_size.should == cache_size
272
- end
273
- end
274
-
275
- describe "ディスプレイ情報を取得できること" do
276
-
277
- it "既知の端末のとき" do
278
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
279
- 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO502i")
280
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
281
- display = @mobile.display
282
- display.should_not be_nil
283
- display.colors.should == 4
284
- display.width.should == 120
285
- display.height.should == 120
286
- end
287
-
288
- it "未知の端末のとき" do
289
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
290
- 'HTTP_USER_AGENT' => 'DoCoMo/1.0/X000i')
291
- @mobile = Rack::Ketai::Carrier::Docomo.new(@env)
292
- display = @mobile.display
293
- display.should_not be_nil
294
- display.colors.should be_nil
295
- display.width.should be_nil
296
- display.height.should be_nil
297
- end
298
-
299
- end
300
-
301
- end
302
-
303
- describe "#supports_cookie? を使うとき" do
304
-
305
- # iモードブラウザ 2.0から対応
306
- # といっても、iモードブラウザ 2.0かどうか判断するには
307
- # キャッシュサイズで調べるしかない(c500)
308
- # キャッシュが不明な場合は端末データベースから判断
309
- # (ただし信頼性が低いので最後の手段)
310
-
311
- it "Cookie対応機種なら true を返すこと" do
312
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
313
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 F02B')
314
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
315
- mobile.should be_respond_to(:supports_cookie?)
316
- mobile.should be_supports_cookie
317
- end
318
-
319
- it "Cookie未対応機種なら false を返すこと" do
320
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
321
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 L06A')
322
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
323
- mobile.should be_respond_to(:supports_cookie?)
324
- mobile.should_not be_supports_cookie
325
- end
326
-
327
- it "不明な機種でもキャッシュサイズがわかればそれを基に判断すること" do
328
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
329
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 X00HOGE3(c500;TB;W24H15)')
330
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
331
- mobile.should be_respond_to(:supports_cookie?)
332
- mobile.should be_supports_cookie
333
-
334
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
335
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 X00HOGE3(c100;TB;W24H15)')
336
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
337
- mobile.should be_respond_to(:supports_cookie?)
338
- mobile.should_not be_supports_cookie
339
- end
340
-
341
- it "不明な機種でキャッシュサイズもわからないなら false を返すこと" do
342
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
343
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 X00HOGE')
344
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
345
- mobile.should be_respond_to(:supports_cookie?)
346
- mobile.should_not be_supports_cookie
347
- end
348
-
349
- end
350
-
351
- end