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,108 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'kconv'
3
- require 'rack/ketai/carrier/general'
4
-
5
- describe Rack::Ketai::Carrier::General::EmoticonFilter, "外部フィルタを適用する時" do
6
-
7
- before(:each) do
8
- @filter = Rack::Ketai::Carrier::General::EmoticonFilter.new(:emoticons_path => '/images/emoticons')
9
- end
10
-
11
- it "emoticons_path が与えられないときはなにもしないこと" do
12
- filter = Rack::Ketai::Carrier::General::EmoticonFilter.new
13
- Rack::Ketai::Carrier::General::EmoticonFilter::EMOJIID_TO_TYPECAST_EMOTICONS.each do |emojiid, filenames|
14
- str = '今日はいい[e:'+format("%03X", emojiid)+']ですね。'
15
- resdata = str
16
-
17
- status, headers, body = filter.outbound(200, { "Content-Type" => "text/html"}, [str])
18
-
19
- body[0].should == resdata
20
- end
21
- filter = Rack::Ketai::Carrier::General::EmoticonFilter.new(:emoticons_path => '')
22
- Rack::Ketai::Carrier::General::EmoticonFilter::EMOJIID_TO_TYPECAST_EMOTICONS.each do |emojiid, filenames|
23
- str = '今日はいい[e:'+format("%03X", emojiid)+']ですね。'
24
- resdata = str
25
-
26
- status, headers, body = filter.outbound(200, { "Content-Type" => "text/html"}, [str])
27
-
28
- body[0].should == resdata
29
- end
30
- end
31
-
32
- it "データ中の絵文字IDをimgタグに変換すること" do
33
- Rack::Ketai::Carrier::General::EmoticonFilter::EMOJIID_TO_TYPECAST_EMOTICONS.each do |emojiid, filenames|
34
- tag = filenames.collect{ |filename| "<img src=\"/images/emoticons/#{filename}.gif\" />" }.join('')
35
- resdata = "今日はいい#{tag}ですね。"
36
-
37
- status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ['今日はいい[e:'+format("%03X", emojiid)+']ですね。'])
38
-
39
- body[0].should == resdata
40
- end
41
- end
42
-
43
- it "データ中に絵文字ID=絵文字IDだが絵文字≠絵文字IDのIDが含まれているとき、正しく逆変換できること" do
44
- resdata = "たとえば<img src=\"/images/emoticons/happy01.gif\" />「e-330 HAPPY FACE WITH OPEN MOUTH」とか。"
45
-
46
- status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ["たとえば[e:330]「e-330 HAPPY FACE WITH OPEN MOUTH」とか。"])
47
-
48
- body[0].should == resdata
49
- end
50
-
51
- it "データ中にTypepad絵文字にはない絵文字IDが存在するとき、代替文字を表示すること" do
52
- resdata = "黒い矢印[#{[0x2190].pack('U')}]です" # 左黒矢印
53
-
54
- status, headers, body = @filter.outbound(200, { "Content-Type" => "text/html"}, ['黒い矢印[e:AFB]です'])
55
-
56
- body[0].should == resdata
57
- end
58
-
59
- it "Content-typeがhtmlでないときには変換しないこと(未設定の場合除く)" do
60
- emojiid = 0x00F
61
- filenames = ["sun","cloud"]
62
- str = '今日はいい[e:'+format("%03X", emojiid)+']ですね。'
63
- tag = filenames.collect{ |filename| "<img src=\"/images/emoticons/#{filename}.gif\" />" }.join('')
64
-
65
- %w(text/plain text/xml text/json application/json text/javascript application/rss+xml image/jpeg).each do |contenttype|
66
- resdata = str
67
-
68
- status, headers, body = @filter.outbound(200, { "Content-Type" => contenttype}, ['今日はいい[e:'+format("%03X", emojiid)+']ですね。'])
69
-
70
- body[0].should == resdata
71
- end
72
-
73
- %w(text/html application/xhtml+xml).each do |contenttype|
74
- resdata = '今日はいい'+tag+'ですね。'
75
-
76
- status, headers, body = @filter.outbound(200, { "Content-Type" => contenttype}, ['今日はいい[e:'+format("%03X", emojiid)+']ですね。'])
77
-
78
- body[0].should == resdata
79
- end
80
-
81
- resdata = '今日はいい'+tag+'ですね。'
82
- status, headers, body = @filter.outbound(200, { "Content-Type" => ''}, ['今日はいい[e:'+format("%03X", emojiid)+']ですね。'])
83
- body[0].should == resdata
84
-
85
- resdata = '今日はいい'+tag+'ですね。'
86
- status, headers, body = @filter.outbound(200, {}, ['今日はいい[e:'+format("%03X", emojiid)+']ですね。'])
87
- body[0].should == resdata
88
-
89
- end
90
-
91
- it "Content-typeは触らないこと" do
92
- [
93
- [nil, nil],
94
- ['text/html'],
95
- ['application/xhtml+xml'],
96
- ['text/javascript'],
97
- ['text/json'],
98
- ['application/json'],
99
- ['text/javascript+json'],
100
- ['image/jpeg'],
101
- ['application/octet-stream'],
102
- ].each do |content_type|
103
- status, headers, body = @filter.outbound(200, { "Content-Type" => content_type}, ['適当な本文'])
104
- headers['Content-Type'].should == content_type
105
- end
106
- end
107
-
108
- end
@@ -1,38 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rack/ketai/carrier/general'
3
- describe Rack::Ketai::Carrier::General do
4
-
5
- before(:each) do
6
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy')
7
- @carrier = Rack::Ketai::Carrier::General.new(@env)
8
- end
9
-
10
- it ":disable_filter オプションを指定しないか false を渡すとフィルタが実行されること" do
11
- options = { }
12
- response = [200, { }, ['']]
13
- mock_filter = mock(Rack::Ketai::Carrier::General::EmoticonFilter)
14
- mock_filter.should_receive(:inbound).once.with(@env).and_return(@env)
15
- mock_filter.should_receive(:outbound).once.with(*response).and_return(response)
16
- Rack::Ketai::Carrier::General::EmoticonFilter.should_receive(:new).at_least(1).with(options).and_return(mock_filter)
17
- @carrier.filtering(@env, options){ |env| response }
18
-
19
- options = { :disable_filter => false }
20
- response = [200, { }, ['']]
21
- mock_filter = mock(Rack::Ketai::Carrier::General::EmoticonFilter)
22
- mock_filter.should_receive(:inbound).once.with(@env).and_return(@env)
23
- mock_filter.should_receive(:outbound).once.with(*response).and_return(response)
24
- Rack::Ketai::Carrier::General::EmoticonFilter.should_receive(:new).at_least(1).with(options).and_return(mock_filter)
25
- @carrier.filtering(@env, options){ |env| response }.should == response
26
- end
27
-
28
- it ":disable_filter オプションに true を渡すと、フィルタが実行されないこと" do
29
- options = { :disable_filter => true }
30
- response = [200, { }, ['']]
31
- mock_filter = mock(Rack::Ketai::Carrier::General::EmoticonFilter)
32
- mock_filter.should_receive(:inbound).exactly(0)
33
- mock_filter.should_receive(:outbound).exactly(0)
34
- Rack::Ketai::Carrier::General::EmoticonFilter.should_receive(:new).any_number_of_times.with(options).and_return(mock_filter)
35
- @carrier.filtering(@env, options){ |env| response }.should == response
36
- end
37
-
38
- end
@@ -1,41 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rack/ketai/carrier/general'
3
- describe "Rack::Ketai::Carrier::General" do
4
-
5
- describe 'PCでのアクセスのとき' do
6
-
7
- before(:each) do
8
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
9
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; ja; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729; .NET4.0E)',
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::General がセットされること' do
28
- @mobile.should be_is_a(Rack::Ketai::Carrier::General)
29
- end
30
-
31
- it '携帯端末でないこと' do
32
- @mobile.should_not be_mobile
33
- end
34
-
35
- it 'スマートフォンでないこと' do
36
- @mobile.should_not be_smartphone
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,146 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rack/ketai/carrier/docomo'
3
-
4
- describe "位置情報を取得するとき" do
5
- describe "DoCoMo端末で" do
6
-
7
- it "#position でGPS位置情報が取得できること" do
8
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?lat=%2B35.00.35.600&lon=%2B135.41.35.600&geo=wgs84&x-acc=3',
9
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 P903i(c10)')
10
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
11
- position = mobile.position
12
- position.should be_instance_of(Rack::Ketai::Position)
13
- format("%.10f", position.lat).should == "35.0098888889"
14
- format("%.10f", position.lng).should == "135.6932222222"
15
- end
16
-
17
- it "取得に失敗したら #position が nil に設定されること" do
18
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
19
- 'HTTP_USER_AGENT' => 'DoCoMo/2.0 P903i(c10)')
20
- mobile = Rack::Ketai::Carrier::Docomo.new(env)
21
- mobile.position.should be_nil
22
- end
23
- end
24
-
25
- describe "au端末で" do
26
-
27
- describe "#position でGPS位置情報が" do
28
- it "WGS84+度分秒単位で渡された場合に取得できること" do
29
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=0&lat=%2B35.00.35.60&lon=%2B135.41.35.60&datum=0',
30
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
31
- mobile = Rack::Ketai::Carrier::Au.new(env)
32
- position = mobile.position
33
- position.should be_instance_of(Rack::Ketai::Position)
34
- format("%.10f", position.lat).should == "35.0098888889"
35
- format("%.10f", position.lng).should == "135.6932222222"
36
-
37
- # +/-が省略
38
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=0&lat=35.00.35.60&lon=135.41.35.60&datum=0',
39
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
40
- mobile = Rack::Ketai::Carrier::Au.new(env)
41
- position = mobile.position
42
- position.should be_instance_of(Rack::Ketai::Position)
43
- format("%.10f", position.lat).should == "35.0098888889"
44
- format("%.10f", position.lng).should == "135.6932222222"
45
- end
46
-
47
- it "WGS84+度単位で渡された場合に取得できること" do
48
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=1&lat=%2B35.00989&lon=%2B135.69322&datum=0',
49
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
50
- mobile = Rack::Ketai::Carrier::Au.new(env)
51
- position = mobile.position
52
- position.should be_instance_of(Rack::Ketai::Position)
53
- format("%.10f", position.lat).should == "35.0098900000"
54
- format("%.10f", position.lng).should == "135.6932200000"
55
-
56
- # +/-が省略
57
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=1&lat=35.00989&lon=135.69322&datum=0',
58
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
59
- mobile = Rack::Ketai::Carrier::Au.new(env)
60
- position = mobile.position
61
- position.should be_instance_of(Rack::Ketai::Position)
62
- format("%.10f", position.lat).should == "35.0098900000"
63
- format("%.10f", position.lng).should == "135.6932200000"
64
- end
65
-
66
- it "TOKYO97+度分秒単位で渡された場合に取得できること" do
67
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=0&lat=%2B35.00.35.60&lon=%2B135.41.35.60&datum=1',
68
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
69
- mobile = Rack::Ketai::Carrier::Au.new(env)
70
- position = mobile.position
71
- position.should be_instance_of(Rack::Ketai::Position)
72
- format("%.10f", position.lat).should == "35.0131010819"
73
- format("%.10f", position.lng).should == "135.6903650621"
74
-
75
- # +/-が省略
76
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=0&lat=35.00.35.60&lon=135.41.35.60&datum=1',
77
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
78
- mobile = Rack::Ketai::Carrier::Au.new(env)
79
- position = mobile.position
80
- position.should be_instance_of(Rack::Ketai::Position)
81
- format("%.10f", position.lat).should == "35.0131010819"
82
- format("%.10f", position.lng).should == "135.6903650621"
83
- end
84
-
85
- it "TOKYO97+度単位で渡された場合に取得できること" do
86
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=1&lat=%2B35.00989&lon=%2B135.69322&datum=1',
87
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
88
- mobile = Rack::Ketai::Carrier::Au.new(env)
89
- position = mobile.position
90
- position.should be_instance_of(Rack::Ketai::Position)
91
- format("%.10f", position.lat).should == "35.0131021928"
92
- format("%.10f", position.lng).should == "135.6903628401"
93
-
94
- # +/-が省略
95
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?var=1&alt=33&time=20100913142300&smaj=104&smin=53&vert=41&majaa=96&fm=2&unit=1&lat=35.00989&lon=135.69322&datum=1',
96
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
97
- mobile = Rack::Ketai::Carrier::Au.new(env)
98
- position = mobile.position
99
- position.should be_instance_of(Rack::Ketai::Position)
100
- format("%.10f", position.lat).should == "35.0131021928"
101
- format("%.10f", position.lng).should == "135.6903628401"
102
- end
103
-
104
- end
105
-
106
- it "取得に失敗したら #position が nil に設定されること" do
107
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
108
- 'HTTP_USER_AGENT' => 'KDDI-SA31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0')
109
- mobile = Rack::Ketai::Carrier::Au.new(env)
110
- mobile.position.should be_nil
111
- end
112
- end
113
-
114
- describe "Softbank端末(3GC)で" do
115
-
116
- it "#position でGPS位置情報(WGS84)が取得できること" do
117
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?pos=N35.00.35.60E135.41.35.60&geo=wgs84&x-acr=3',
118
- 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1')
119
- mobile = Rack::Ketai::Carrier::Softbank.new(env)
120
- position = mobile.position
121
- position.should be_instance_of(Rack::Ketai::Position)
122
- format("%.10f", position.lat).should == "35.0098888889"
123
- format("%.10f", position.lng).should == "135.6932222222"
124
- end
125
-
126
- it "#position でGPS位置情報(TOKYO)が取得できること" do
127
- env = Rack::MockRequest.env_for('http://hoge.com/dummy?pos=N35.00.35.60E135.41.35.60&geo=tokyo&x-acr=3',
128
- 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1')
129
- mobile = Rack::Ketai::Carrier::Softbank.new(env)
130
- position = mobile.position
131
- position.should be_instance_of(Rack::Ketai::Position)
132
- format("%.10f", position.lat).should == "35.0131010819"
133
- format("%.10f", position.lng).should == "135.6903650621"
134
- end
135
-
136
-
137
- it "取得に失敗したら #position が nil に設定されること" do
138
- env = Rack::MockRequest.env_for('http://hoge.com/dummy',
139
- 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1')
140
- mobile = Rack::Ketai::Carrier::Softbank.new(env)
141
- mobile.position.should be_nil
142
- end
143
- end
144
-
145
- end
146
-
@@ -1,95 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rack/ketai/carrier/iphone'
3
- describe "Rack::Ketai::Carrier::IPhone" do
4
-
5
- describe 'iPhoneでのアクセスのとき' do
6
-
7
- before(:each) do
8
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
9
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7',
10
- 'REMOTE_ADDR' => '126.240.0.41')
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::IPhone がセットされること' do
28
- @mobile.should be_is_a(Rack::Ketai::Carrier::IPhone)
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
- describe 'iPodでのアクセスのとき' do
51
-
52
- before(:each) do
53
- @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
54
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3',
55
- 'REMOTE_ADDR' => '126.240.0.41')
56
- @mobile = Rack::Ketai::Carrier.load(@env)
57
- end
58
-
59
- it 'PC向け絵文字フィルタが適用されること' do
60
- mock_app = mock('App')
61
- mock_app.should_receive(:call).twice do |env|
62
- [200, { "Content-Type" => "text/html"}, ["今日は良い天気ですね[e:000]"]]
63
- end
64
-
65
- middleware = Rack::Ketai::Middleware.new(mock_app, {})
66
- middleware.call(@env)[2].should == ['今日は良い天気ですね[e:000]']
67
-
68
- middleware = Rack::Ketai::Middleware.new(mock_app, { :emoticons_path => '/path-to/emoticons' })
69
- middleware.call(@env)[2].should == ['今日は良い天気ですね<img src="/path-to/emoticons/sun.gif" />']
70
- end
71
-
72
- it 'Rack::Ketai::Carrier::IPhone がセットされること' do
73
- @mobile.should be_is_a(Rack::Ketai::Carrier::IPhone)
74
- end
75
-
76
- it '携帯端末であること' do
77
- @mobile.should be_mobile
78
- end
79
-
80
- it 'スマートフォンであること' do
81
- @mobile.should be_smartphone
82
- end
83
-
84
- it "#supports_cookie? は true を返すこと" do
85
- @mobile.should be_respond_to(:supports_cookie?)
86
- @mobile.should be_supports_cookie
87
- end
88
-
89
- it "#valid_addr? は false を返すこと" do
90
- @mobile.should_not be_valid_addr
91
- end
92
-
93
- end
94
-
95
- end
@@ -1,38 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- describe Rack::Ketai::Middleware, "#call を実行するとき" do
4
-
5
- it "適切な env['rack.ketai'] を設定できること" 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
- mock_env = Rack::MockRequest.env_for('http://hoge.com/dummy','HTTP_USER_AGENT' => ua)
20
-
21
- mock_app = mock('App')
22
- mock_app.should_receive(:call) do |env|
23
- if carrier
24
- env['rack.ketai'].should_not be_nil
25
- env['rack.ketai'].mobile?.should be_true
26
- else
27
- env['rack.ketai'].should be_nil
28
- env['rack.ketai'].mobile?.should be_false
29
- end
30
- [200, { "Content-Type" => "text/plain"}, ["OK"]]
31
- end
32
-
33
- middleware = Rack::Ketai::Middleware.new(mock_app, { })
34
- middleware.call(mock_env)
35
- end
36
- end
37
-
38
- end