jpmobile 0.0.8 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -3
- data/{spec/spec.opts → .rspec} +1 -2
- data/README.rdoc +122 -128
- data/Rakefile +23 -101
- data/VERSION.yml +4 -3
- data/jpmobile.gemspec +130 -182
- data/lib/jpmobile.rb +37 -24
- data/lib/jpmobile/docomo_guid.rb +2 -1
- data/lib/jpmobile/email.rb +3 -4
- data/lib/jpmobile/emoticon.rb +2 -6
- data/lib/jpmobile/encoding.rb +29 -0
- data/lib/jpmobile/filter.rb +42 -134
- data/lib/jpmobile/helpers.rb +5 -18
- data/lib/jpmobile/hook_action_controller.rb +24 -16
- data/lib/jpmobile/hook_action_view.rb +28 -89
- data/lib/jpmobile/mobile/abstract_mobile.rb +21 -4
- data/lib/jpmobile/mobile/android.rb +10 -0
- data/lib/jpmobile/mobile/au.rb +28 -3
- data/lib/jpmobile/mobile/ddipocket.rb +12 -0
- data/lib/jpmobile/mobile/display.rb +29 -26
- data/lib/jpmobile/mobile/docomo.rb +38 -12
- data/lib/jpmobile/mobile/iphone.rb +26 -0
- data/lib/jpmobile/mobile/smart_phone.rb +21 -0
- data/lib/jpmobile/mobile/softbank.rb +16 -41
- data/lib/jpmobile/mobile/vodafone.rb +17 -0
- data/lib/jpmobile/mobile/willcom.rb +1 -10
- data/lib/jpmobile/mobile/windows_phone.rb +10 -0
- data/lib/jpmobile/position.rb +4 -3
- data/lib/jpmobile/rack.rb +43 -0
- data/lib/jpmobile/rack/filter.rb +51 -0
- data/lib/jpmobile/rack/mobile_carrier.rb +33 -0
- data/lib/jpmobile/rack/params_filter.rb +47 -0
- data/lib/jpmobile/rails.rb +22 -0
- data/lib/jpmobile/request_with_mobile.rb +8 -12
- data/lib/jpmobile/trans_sid.rb +44 -26
- data/lib/jpmobile/util.rb +68 -0
- data/{tasks → lib/tasks}/jpmobile_tasks.rake +32 -13
- data/spec/rack/jpmobile/android_spec.rb +20 -0
- data/spec/rack/jpmobile/au_spec.rb +206 -0
- data/spec/rack/jpmobile/docomo_spec.rb +237 -0
- data/spec/rack/jpmobile/emoticon_spec.rb +215 -0
- data/spec/rack/jpmobile/filter_spec.rb +181 -0
- data/spec/rack/jpmobile/iphone_spec.rb +32 -0
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +39 -0
- data/spec/rack/jpmobile/params_filter_spec.rb +193 -0
- data/spec/rack/jpmobile/softbank_spec.rb +123 -0
- data/spec/rack/jpmobile/willcom_spec.rb +67 -0
- data/spec/rack/jpmobile/windows_phone.rb +20 -0
- data/spec/rack_helper.rb +86 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/unit/detect_by_email_spec.rb +21 -27
- data/spec/unit/is_carrier_spec.rb +56 -84
- data/spec/unit/spec_helper.rb +1 -2
- data/spec/unit/util_spec.rb +2 -2
- data/spec/unit/valid_ip_spec.rb +43 -52
- data/test/legacy/autoload_test.rb +1 -3
- data/test/legacy/emoticon_test.rb +5 -6
- data/test/legacy/helper.rb +0 -71
- data/test/rails/overrides/.rspec +5 -0
- data/test/rails/overrides/Gemfile +32 -0
- data/test/rails/overrides/app/controllers/docomo_guid_always_controller.rb +3 -0
- data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +5 -0
- data/test/rails/overrides/app/controllers/docomo_guid_docomo_controller.rb +3 -0
- data/test/rails/overrides/app/controllers/filter_controller.rb +0 -34
- data/test/rails/overrides/app/controllers/filter_controller_base.rb +19 -0
- data/test/rails/overrides/app/controllers/hankaku_filter_controller.rb +3 -0
- data/test/rails/overrides/app/controllers/links_controller.rb +28 -0
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
- data/test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb +4 -0
- data/test/rails/overrides/app/controllers/trans_sid_always_controller.rb +3 -0
- data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -0
- data/test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb +3 -0
- data/test/rails/overrides/app/controllers/trans_sid_none_controller.rb +3 -0
- data/test/rails/overrides/app/views/links/au_gps.html.erb +1 -0
- data/test/rails/overrides/app/views/links/au_location.html.erb +1 -0
- data/test/rails/overrides/app/views/links/docomo_foma_gps.html.erb +1 -0
- data/test/rails/overrides/app/views/links/docomo_openiarea.html.erb +1 -0
- data/test/rails/overrides/app/views/links/docomo_utn.html.erb +1 -0
- data/test/rails/overrides/app/views/links/link.html.erb +1 -0
- data/test/rails/overrides/app/views/links/show_all.html.erb +1 -0
- data/test/rails/overrides/app/views/links/softbank_location.html.erb +1 -0
- data/test/rails/overrides/app/views/links/willcom_location.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/_partial_smart_phone.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/_partial_smart_phone_iphone.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index_smart_phone.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index_smart_phone_iphone.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/show_mobile.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/show_mobile_docomo.html.erb +1 -0
- data/test/rails/overrides/autotest/discover.rb +2 -0
- data/test/rails/overrides/config/initializers/jpmobile_generator.rb +1 -0
- data/test/rails/overrides/config/routes.rb +58 -0
- data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +16 -0
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -2
- data/test/rails/overrides/spec/{controllers → requests}/docomo_guid_spec.rb +37 -14
- data/test/rails/overrides/spec/{controllers → requests}/docomo_spec.rb +11 -8
- data/test/rails/overrides/spec/{controllers → requests}/emobile_spec.rb +24 -8
- data/test/rails/overrides/spec/requests/filter_spec.rb +171 -0
- data/test/rails/overrides/spec/requests/helpers_spec.rb +187 -0
- data/test/rails/overrides/spec/requests/pc_spec.rb +22 -0
- data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +21 -0
- data/test/rails/overrides/spec/requests/template_path_spec.rb +234 -0
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +142 -0
- data/test/rails/overrides/spec/spec_helper.rb +17 -48
- data/test/sinatra/guestbook.rb +40 -0
- data/test/sinatra/test/filter_test.rb +39 -0
- metadata +185 -312
- data/lib/jpmobile/hook_request.rb +0 -5
- data/lib/jpmobile/rack/auth.rb +0 -55
- data/lib/jpmobile/rack/combined_logger.rb +0 -54
- data/lib/jpmobile/rack/request.rb +0 -7
- data/lib/jpmobile/rack/trans_sid.rb +0 -14
- data/lib/jpmobile/version.rb +0 -9
- data/spec/unit/detect_by_ua_spec.rb +0 -40
- data/test/legacy/au_test.rb +0 -173
- data/test/legacy/docomo_test.rb +0 -187
- data/test/legacy/emoticon_functional_test.rb +0 -195
- data/test/legacy/filter_test.rb +0 -34
- data/test/legacy/helpers_test.rb +0 -217
- data/test/legacy/softbank_test.rb +0 -183
- data/test/legacy/willcom_test.rb +0 -56
- data/test/rails/2.3.2/spec/controllers/trans_sid_spec.rb +0 -99
- data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +0 -13
- data/test/rails/overrides/app/controllers/trans_sid_controller.rb +0 -28
- data/test/rails/overrides/lib/tasks/rspec.rake +0 -165
- data/test/rails/overrides/spec/controllers/filter_spec.rb +0 -159
- data/test/rails/overrides/spec/controllers/pc_spec.rb +0 -13
- data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +0 -42
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +0 -117
- data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +0 -117
- data/test/rails/overrides/spec/rspec.rake +0 -165
- data/test/rails/overrides/spec/spec.opts +0 -4
@@ -0,0 +1,193 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::ParamsFilter do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
include Jpmobile::RackHelper
|
7
|
+
include Jpmobile::Util
|
8
|
+
|
9
|
+
context "漢字コード変換" do
|
10
|
+
before(:each) do
|
11
|
+
@query_params = {
|
12
|
+
"hoge" => "ほげ",
|
13
|
+
"パラメータ" => "テストです■",
|
14
|
+
}
|
15
|
+
@form_params = {
|
16
|
+
"bar" => "万葉集",
|
17
|
+
"アジャイル" => "僕の♪",
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
context "Shift_JIS 変換の " do
|
22
|
+
before(:each) do
|
23
|
+
@query_string = @query_params.map {|k, v|
|
24
|
+
"%s=%s" % [::Rack::Utils.escape(NKF.nkf("-sWx", k)), ::Rack::Utils.escape(NKF.nkf("-sWx", v))]
|
25
|
+
}.join("&")
|
26
|
+
@form_string = @form_params.map {|k, v|
|
27
|
+
"%s=%s" % [NKF.nkf("-sWx", k), NKF.nkf("-sWx", v)]
|
28
|
+
}.join("&")
|
29
|
+
end
|
30
|
+
|
31
|
+
context "docomo のとき" do
|
32
|
+
it "Shift_JIS が UTF-8 に変換されること" do
|
33
|
+
res = Rack::MockRequest.env_for(
|
34
|
+
"/?#{@query_string}",
|
35
|
+
"REQUEST_METHOD" => "POST",
|
36
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
37
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)',
|
38
|
+
:input => @form_string)
|
39
|
+
|
40
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
41
|
+
req = Rack::Request.new(res[1])
|
42
|
+
req.params.size.should == 4
|
43
|
+
|
44
|
+
req.params[ascii_8bit(@query_params.keys.first.dup)].should == ascii_8bit(@query_params[@query_params.keys.first])
|
45
|
+
req.params[ascii_8bit(@query_params.keys.last.dup)].should == ascii_8bit(@query_params[@query_params.keys.last])
|
46
|
+
|
47
|
+
req.params[ascii_8bit(@form_params.keys.first.dup)].should == ascii_8bit(@form_params[@form_params.keys.first])
|
48
|
+
req.params[ascii_8bit(@form_params.keys.last.dup)].should == ascii_8bit(@form_params[@form_params.keys.last])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "au のとき" do
|
53
|
+
it "Shift_JIS が UTF-8 に変換されること" do
|
54
|
+
res = Rack::MockRequest.env_for(
|
55
|
+
"/?#{@query_string}",
|
56
|
+
"REQUEST_METHOD" => "POST",
|
57
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
58
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
|
59
|
+
:input => @form_string)
|
60
|
+
|
61
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
62
|
+
req = Rack::Request.new(res[1])
|
63
|
+
req.params.size.should == 4
|
64
|
+
|
65
|
+
req.params[ascii_8bit(@query_params.keys.first.dup)].should == ascii_8bit(@query_params[@query_params.keys.first])
|
66
|
+
req.params[ascii_8bit(@query_params.keys.last.dup)].should == ascii_8bit(@query_params[@query_params.keys.last])
|
67
|
+
|
68
|
+
req.params[ascii_8bit(@form_params.keys.first.dup)].should == ascii_8bit(@form_params[@form_params.keys.first])
|
69
|
+
req.params[ascii_8bit(@form_params.keys.last.dup)].should == ascii_8bit(@form_params[@form_params.keys.last])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "UTF-8 の" do
|
75
|
+
before(:each) do
|
76
|
+
@query_string = @query_params.map {|k, v|
|
77
|
+
"%s=%s" % [::Rack::Utils.escape(k), ::Rack::Utils.escape(v)]
|
78
|
+
}.join("&")
|
79
|
+
@form_string = @form_params.map {|k, v|
|
80
|
+
"%s=%s" % [k, v]
|
81
|
+
}.join("&")
|
82
|
+
end
|
83
|
+
|
84
|
+
context "softbank のとき" do
|
85
|
+
it "変換されないこと" do
|
86
|
+
res = Rack::MockRequest.env_for(
|
87
|
+
"/?#{@query_string}",
|
88
|
+
"REQUEST_METHOD" => "POST",
|
89
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
90
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1",
|
91
|
+
:input => @form_string)
|
92
|
+
|
93
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
94
|
+
req = Rack::Request.new(res[1])
|
95
|
+
req.params.size.should == 4
|
96
|
+
|
97
|
+
req.params[ascii_8bit(@query_params.keys.first.dup)].should == ascii_8bit(@query_params[@query_params.keys.first])
|
98
|
+
req.params[ascii_8bit(@query_params.keys.last.dup)].should == ascii_8bit(@query_params[@query_params.keys.last])
|
99
|
+
|
100
|
+
req.params[ascii_8bit(@form_params.keys.first.dup)].should == ascii_8bit(@form_params[@form_params.keys.first])
|
101
|
+
req.params[ascii_8bit(@form_params.keys.last.dup)].should == ascii_8bit(@form_params[@form_params.keys.last])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "絵文字変換" do
|
108
|
+
context "docomo の場合" do
|
109
|
+
it "Shift_JIS 絵文字がUTF-8に変換されること" do
|
110
|
+
query_string = "hoge=" + ::Rack::Utils.escape(sjis("\xf8\x9f"))
|
111
|
+
form_string = "foo=" + sjis("\xf8\xa1")
|
112
|
+
|
113
|
+
res = Rack::MockRequest.env_for(
|
114
|
+
"/?#{query_string}",
|
115
|
+
"REQUEST_METHOD" => "POST",
|
116
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
117
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)',
|
118
|
+
:input => form_string)
|
119
|
+
|
120
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
121
|
+
req = Rack::Request.new(res[1])
|
122
|
+
req.params.size.should == 2
|
123
|
+
|
124
|
+
req.params["hoge"].should == ascii_8bit("\356\230\276")
|
125
|
+
req.params["foo"].should == ascii_8bit("\356\231\200")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "au の場合" do
|
130
|
+
it "Shift_JIS 絵文字がUTF-8に変換されること" do
|
131
|
+
query_string = "hoge=" + ::Rack::Utils.escape(sjis("\xf6\x59"))
|
132
|
+
form_string = "foo=" + sjis("\xf6\xfb")
|
133
|
+
|
134
|
+
res = Rack::MockRequest.env_for(
|
135
|
+
"/?#{query_string}",
|
136
|
+
"REQUEST_METHOD" => "POST",
|
137
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
138
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
|
139
|
+
:input => form_string)
|
140
|
+
|
141
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
142
|
+
req = Rack::Request.new(res[1])
|
143
|
+
req.params.size.should == 2
|
144
|
+
|
145
|
+
req.params["hoge"].should == ascii_8bit("\356\222\201")
|
146
|
+
req.params["foo"].should == ascii_8bit("\356\224\242")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "Softbank の場合" do
|
151
|
+
it "UTF-8 絵文字がUTF-8に変換されること" do
|
152
|
+
query_string = ascii_8bit("hoge=" + ::Rack::Utils.escape([0xe001].pack('U')))
|
153
|
+
form_string = ascii_8bit("foo=" + [0xe21c].pack('U'))
|
154
|
+
|
155
|
+
res = Rack::MockRequest.env_for(
|
156
|
+
"/?#{query_string}",
|
157
|
+
"REQUEST_METHOD" => "POST",
|
158
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
159
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1",
|
160
|
+
:input => form_string)
|
161
|
+
|
162
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
163
|
+
req = Rack::Request.new(res[1])
|
164
|
+
req.params.size.should == 2
|
165
|
+
|
166
|
+
req.params["hoge"].should == ascii_8bit("\xef\x80\x81")
|
167
|
+
req.params["foo"].should == ascii_8bit("\xef\x88\x9c")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "パラメータの変換で" do
|
173
|
+
context "値として" do
|
174
|
+
it "+ が入ってるものが正確に取得できること(token)" do
|
175
|
+
token = "lm/3Pu6RrY+kp8hsnEWp2xygYLInZIxwsB3UWeksaHQ="
|
176
|
+
form_string = ascii_8bit("foo=#{::Rack::Utils.escape(token)}")
|
177
|
+
|
178
|
+
res = Rack::MockRequest.env_for(
|
179
|
+
"/",
|
180
|
+
"REQUEST_METHOD" => "POST",
|
181
|
+
"CONTENT_TYPE" => 'application/x-www-form-urlencoded',
|
182
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1",
|
183
|
+
:input => form_string)
|
184
|
+
|
185
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(UnitApplication.new)).call(res)
|
186
|
+
req = Rack::Request.new(res[1])
|
187
|
+
req.params.size.should == 1
|
188
|
+
|
189
|
+
req.params["foo"].should == ascii_8bit(token)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::MobileCarrier, "softbank" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
context "端末種別で" do
|
8
|
+
it "910T を判別できること" do
|
9
|
+
res = Rack::MockRequest.env_for(
|
10
|
+
'http://jpmobile-rails.org/',
|
11
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
12
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
13
|
+
|
14
|
+
env['rack.jpmobile'].class.should == Jpmobile::Mobile::Softbank
|
15
|
+
env['rack.jpmobile'].position.should be_nil
|
16
|
+
env['rack.jpmobile'].serial_number.should == "000000000000000"
|
17
|
+
env['rack.jpmobile'].ident.should == "000000000000000"
|
18
|
+
env['rack.jpmobile'].ident_device.should == "000000000000000"
|
19
|
+
env['rack.jpmobile'].ident_subscriber.should be_nil
|
20
|
+
env['rack.jpmobile'].supports_cookie?.should be_true
|
21
|
+
env['rack.jpmobile'].smart_phone?.should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "X_JPHONE_UID 付きの 910T を判別できること" do
|
25
|
+
res = Rack::MockRequest.env_for(
|
26
|
+
'http://jpmobile-rails.org/',
|
27
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1",
|
28
|
+
"HTTP_X_JPHONE_UID" => "aaaaaaaaaaaaaaaa")
|
29
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
30
|
+
|
31
|
+
env['rack.jpmobile'].serial_number.should == "000000000000000"
|
32
|
+
env['rack.jpmobile'].x_jphone_uid.should == "aaaaaaaaaaaaaaaa"
|
33
|
+
env['rack.jpmobile'].ident.should == "aaaaaaaaaaaaaaaa"
|
34
|
+
env['rack.jpmobile'].ident_device.should == "000000000000000"
|
35
|
+
env['rack.jpmobile'].ident_subscriber.should == "aaaaaaaaaaaaaaaa"
|
36
|
+
env['rack.jpmobile'].supports_cookie?.should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "V903T を判別できること" do
|
40
|
+
res = Rack::MockRequest.env_for(
|
41
|
+
'http://jpmobile-rails.org/',
|
42
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0")
|
43
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
44
|
+
|
45
|
+
env['rack.jpmobile'].class.should == Jpmobile::Mobile::Vodafone
|
46
|
+
env['rack.jpmobile'].position.should be_nil
|
47
|
+
env['rack.jpmobile'].ident.should be_nil
|
48
|
+
env['rack.jpmobile'].supports_cookie?.should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "GPS で" do
|
53
|
+
it "位置情報が取得できること" do
|
54
|
+
res = Rack::MockRequest.env_for(
|
55
|
+
'http://jpmobile-rails.org/',
|
56
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
|
57
|
+
"QUERY_STRING" => "pos=N43.3.18.42E141.21.1.88&geo=wgs84&x-acr=1")
|
58
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
59
|
+
|
60
|
+
env['rack.jpmobile'].position.lat.should be_close(43.05511667, 1e-7)
|
61
|
+
env['rack.jpmobile'].position.lon.should be_close(141.3505222, 1e-7)
|
62
|
+
env['rack.jpmobile'].position.options['pos'].should == "N43.3.18.42E141.21.1.88"
|
63
|
+
env['rack.jpmobile'].position.options['geo'].should == "wgs84"
|
64
|
+
env['rack.jpmobile'].position.options['x-acr'].should == "1"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "IPアドレス制限で" do
|
69
|
+
it "正しいIPアドレス空間からのアクセスを判断できること" do
|
70
|
+
res = Rack::MockRequest.env_for(
|
71
|
+
'http://jpmobile-rails.org/',
|
72
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
|
73
|
+
"REMOTE_ADDR"=>"202.179.204.1")
|
74
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
75
|
+
|
76
|
+
env['rack.jpmobile'].valid_ip?.should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "正しくないIPアドレス空間からのアクセスを判断できること" do
|
80
|
+
res = Rack::MockRequest.env_for(
|
81
|
+
'http://jpmobile-rails.org/',
|
82
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
|
83
|
+
"REMOTE_ADDR"=>"127.0.0.1")
|
84
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
85
|
+
|
86
|
+
env['rack.jpmobile'].valid_ip?.should be_false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "画面情報で" do
|
91
|
+
it "端末の画面サイズを正しく取得できること" do
|
92
|
+
res = Rack::MockRequest.env_for(
|
93
|
+
'http://jpmobile-rails.org/',
|
94
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
|
95
|
+
"HTTP_X_JPHONE_DISPLAY"=>"240*320",
|
96
|
+
"HTTP_X_JPHONE_COLOR"=>"C262144")
|
97
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
98
|
+
|
99
|
+
env['rack.jpmobile'].display.width.should == 240
|
100
|
+
env['rack.jpmobile'].display.height.should == 320
|
101
|
+
env['rack.jpmobile'].display.physical_width.should == 240
|
102
|
+
env['rack.jpmobile'].display.physical_height.should == 320
|
103
|
+
env['rack.jpmobile'].display.color?.should be_true
|
104
|
+
env['rack.jpmobile'].display.colors.should == 262144
|
105
|
+
end
|
106
|
+
|
107
|
+
it "端末の画面情報が渡ってない場合に正しく動作すること" do
|
108
|
+
res = Rack::MockRequest.env_for(
|
109
|
+
'http://jpmobile-rails.org/',
|
110
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0")
|
111
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
112
|
+
|
113
|
+
env['rack.jpmobile'].display.width.should be_nil
|
114
|
+
env['rack.jpmobile'].display.height.should be_nil
|
115
|
+
env['rack.jpmobile'].display.browser_width.should be_nil
|
116
|
+
env['rack.jpmobile'].display.browser_height.should be_nil
|
117
|
+
env['rack.jpmobile'].display.physical_width.should be_nil
|
118
|
+
env['rack.jpmobile'].display.physical_height.should be_nil
|
119
|
+
env['rack.jpmobile'].display.color?.should be_nil
|
120
|
+
env['rack.jpmobile'].display.colors.should be_nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::MobileCarrier, "willcom" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
context "端末種別で" do
|
8
|
+
it "WX310K が判別できること" do
|
9
|
+
res = Rack::MockRequest.env_for(
|
10
|
+
'http://jpmobile-rails.org/',
|
11
|
+
'HTTP_USER_AGENT' => "Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0")
|
12
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
13
|
+
|
14
|
+
env['rack.jpmobile'].class.should == Jpmobile::Mobile::Willcom
|
15
|
+
env['rack.jpmobile'].position.should be_nil
|
16
|
+
env['rack.jpmobile'].ident.should be_nil
|
17
|
+
env['rack.jpmobile'].supports_cookie?.should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "AH-H3001V が判別できること" do
|
21
|
+
res = Rack::MockRequest.env_for(
|
22
|
+
'http://jpmobile-rails.org/',
|
23
|
+
'HTTP_USER_AGENT' => "Mozilla/3.0(DDIPOCKET;KYOCERA/AH-K3001V/1.8.2.71.000000/0.1/C100) Opera 7.0")
|
24
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
25
|
+
|
26
|
+
env['rack.jpmobile'].class.should == Jpmobile::Mobile::Ddipocket
|
27
|
+
env['rack.jpmobile'].position.should be_nil
|
28
|
+
env['rack.jpmobile'].ident.should be_nil
|
29
|
+
env['rack.jpmobile'].supports_cookie?.should be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "GPS で" do
|
34
|
+
it "緯度経度を取得できること" do
|
35
|
+
res = Rack::MockRequest.env_for(
|
36
|
+
'http://jpmobile-rails.org/',
|
37
|
+
'HTTP_USER_AGENT' => "Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0",
|
38
|
+
"QUERY_STRING" => "pos=N43.04.34.049E141.21.03.279")
|
39
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
40
|
+
|
41
|
+
env['rack.jpmobile'].position.lat.should be_close(43.078568, 1e-4)
|
42
|
+
env['rack.jpmobile'].position.lon.should be_close(141.347223, 1e-4)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "IPアドレス制限で" do
|
47
|
+
it "正しいIPアドレス空間からのアクセスを判断できること" do
|
48
|
+
res = Rack::MockRequest.env_for(
|
49
|
+
'http://jpmobile-rails.org/',
|
50
|
+
'HTTP_USER_AGENT' => "Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0",
|
51
|
+
"REMOTE_ADDR" => "61.198.142.1")
|
52
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
53
|
+
|
54
|
+
env['rack.jpmobile'].valid_ip?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "正しくないIPアドレス空間からのアクセスを判断できること" do
|
58
|
+
res = Rack::MockRequest.env_for(
|
59
|
+
'http://jpmobile-rails.org/',
|
60
|
+
'HTTP_USER_AGENT' => "Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0",
|
61
|
+
"REMOTE_ADDR" => "127.0.0.1")
|
62
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
63
|
+
|
64
|
+
env['rack.jpmobile'].valid_ip?.should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::MobileCarrier, "Windows Phone" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
context "端末種別で" do
|
8
|
+
it "WindowsPhone を判別できること" do
|
9
|
+
res = Rack::MockRequest.env_for(
|
10
|
+
'http://jpmobile-rails.org/',
|
11
|
+
'HTTP_USER_AGENT' => 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)')
|
12
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
13
|
+
|
14
|
+
env['rack.jpmobile'].class.should == Jpmobile::Mobile::WindowsPhone
|
15
|
+
env['rack.jpmobile'].position.should be_nil
|
16
|
+
env['rack.jpmobile'].smart_phone?.should be_true
|
17
|
+
env['rack.jpmobile'].supports_cookie?.should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/rack_helper.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# spec/spec_helper.rb
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'rspec'
|
5
|
+
require 'jpmobile'
|
6
|
+
require 'jpmobile/rack'
|
7
|
+
require 'pp' # for debug
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include Rack::Test::Methods
|
11
|
+
end
|
12
|
+
|
13
|
+
class UnitApplication
|
14
|
+
def initialize(body = nil)
|
15
|
+
@body = body || "Body"
|
16
|
+
if @body.respond_to?(:force_encoding)
|
17
|
+
@body.force_encoding("UTF-8")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(env)
|
22
|
+
Rack::Response.new(@body, 200, env).finish
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ParamsApplication
|
27
|
+
def initialize(app, form, query)
|
28
|
+
@app = app
|
29
|
+
@form = form
|
30
|
+
@query = query
|
31
|
+
end
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
env['rack.request.form_hash'] = @form
|
35
|
+
env['rack.request.query_hash'] = @query
|
36
|
+
|
37
|
+
@app.call(env)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class RenderParamApp
|
42
|
+
def call(env)
|
43
|
+
request = Rack::Request.new(env)
|
44
|
+
q = request.params['q']
|
45
|
+
if q.respond_to?(:force_encoding)
|
46
|
+
q.force_encoding("UTF-8")
|
47
|
+
end
|
48
|
+
|
49
|
+
[200, env, q]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Jpmobile::RackHelper
|
54
|
+
def user_agent(str)
|
55
|
+
@request.user_agent = str
|
56
|
+
end
|
57
|
+
def init(c)
|
58
|
+
@controller = c.new
|
59
|
+
@controller.logger = Logger.new(nil)
|
60
|
+
@request = ActionController::TestRequest.new
|
61
|
+
@response = ActionController::TestResponse.new
|
62
|
+
@request.host = "www.example.jp"
|
63
|
+
@request.session.session_id = "mysessionid"
|
64
|
+
end
|
65
|
+
include Jpmobile::Util
|
66
|
+
|
67
|
+
def response_body(res)
|
68
|
+
body = case res
|
69
|
+
when Array
|
70
|
+
res[2].body
|
71
|
+
when String
|
72
|
+
res.body
|
73
|
+
else
|
74
|
+
res.body
|
75
|
+
end
|
76
|
+
|
77
|
+
case body
|
78
|
+
when Array
|
79
|
+
body.first
|
80
|
+
when String
|
81
|
+
body
|
82
|
+
else
|
83
|
+
body
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|