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,215 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe "絵文字が" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
include Jpmobile::RackHelper
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@docomo_cr = "";
|
10
|
+
@docomo_utf8 = [0xe63e].pack("U")
|
11
|
+
@docomo_docomopoint = ""
|
12
|
+
|
13
|
+
@au_cr = ""
|
14
|
+
@au_utf8 = [0xe488].pack("U")
|
15
|
+
|
16
|
+
@softbank_cr = ""
|
17
|
+
@softbank_utf8 = [0xf04a].pack("U")
|
18
|
+
end
|
19
|
+
|
20
|
+
context "PC のとき" do
|
21
|
+
before(:each) do
|
22
|
+
@res = Rack::MockRequest.env_for("/")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "docomo 絵文字が変換されないこと" do
|
26
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_cr))).call(@res)[2]
|
27
|
+
response_body(response).should == @docomo_cr
|
28
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_utf8))).call(@res)[2]
|
29
|
+
response_body(response).should == @docomo_utf8
|
30
|
+
end
|
31
|
+
|
32
|
+
it "au 絵文字が変換されないこと" do
|
33
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_cr))).call(@res)[2]
|
34
|
+
response_body(response).should == @au_cr
|
35
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_utf8))).call(@res)[2]
|
36
|
+
response_body(response).should == @au_utf8
|
37
|
+
end
|
38
|
+
|
39
|
+
it "softbank 絵文字が変換されないこと" do
|
40
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
|
41
|
+
response_body(response).should == @softbank_cr
|
42
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
|
43
|
+
response_body(response).should == @softbank_utf8
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "docomo のとき" do
|
48
|
+
before(:each) do
|
49
|
+
@res = Rack::MockRequest.env_for(
|
50
|
+
"/",
|
51
|
+
'HTTP_USER_AGENT' => "DoCoMo/2.0 SH902i(c100;TB;W24H12)")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "docomo 絵文字が変換されること" do
|
55
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_cr))).call(@res)[2]
|
56
|
+
response_body(response).should == sjis("\xf8\x9f")
|
57
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_utf8))).call(@res)[2]
|
58
|
+
response_body(response).should == sjis("\xf8\x9f")
|
59
|
+
|
60
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_docomopoint))).call(@res)[2]
|
61
|
+
response_body(response).should == sjis("\xf9\x79")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "au 絵文字が変換されること" do
|
65
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_cr))).call(@res)[2]
|
66
|
+
response_body(response).should == sjis("\xf8\x9f")
|
67
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_utf8))).call(@res)[2]
|
68
|
+
response_body(response).should == sjis("\xf8\x9f")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "softbank 絵文字が変換されること" do
|
72
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
|
73
|
+
response_body(response).should == sjis("\xf8\x9f")
|
74
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
|
75
|
+
response_body(response).should == sjis("\xf8\x9f")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "パラメータが変換されること" do
|
79
|
+
query_string = "q=" + URI.encode(sjis("\xf8\x9f"))
|
80
|
+
if query_string.respond_to?(:force_encoding)
|
81
|
+
query_string.force_encoding("ASCII-8BIT")
|
82
|
+
end
|
83
|
+
|
84
|
+
res = Rack::MockRequest.env_for(
|
85
|
+
"/?#{query_string}",
|
86
|
+
"REQUEST_METHOD" => "GET",
|
87
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
88
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
|
89
|
+
req = Rack::Request.new(res[1])
|
90
|
+
req.params['q'].should == utf8("\xee\x98\xbe")
|
91
|
+
response_body(res).should == sjis("\xf8\x9f")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "au のとき" do
|
96
|
+
before(:each) do
|
97
|
+
@res = Rack::MockRequest.env_for(
|
98
|
+
"/",
|
99
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "docomo 絵文字が変換されること" do
|
103
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_cr))).call(@res)[2]
|
104
|
+
response_body(response).should == sjis("\xf6\x60")
|
105
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_utf8))).call(@res)[2]
|
106
|
+
response_body(response).should == sjis("\xf6\x60")
|
107
|
+
|
108
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_docomopoint))).call(@res)[2]
|
109
|
+
response_body(response).should == utf8_to_sjis("[ドコモポイント]")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "au 絵文字が変換されること" do
|
113
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_cr))).call(@res)[2]
|
114
|
+
response_body(response).should == sjis("\xf6\x60")
|
115
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_utf8))).call(@res)[2]
|
116
|
+
response_body(response).should == sjis("\xf6\x60")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "softbank 絵文字が変換されること" do
|
120
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
|
121
|
+
response_body(response).should == sjis("\xf6\x60")
|
122
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
|
123
|
+
response_body(response).should == sjis("\xf6\x60")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "パラメータが変換されること" do
|
127
|
+
query_string = "q=" + URI.encode(sjis("\xf6\x60"))
|
128
|
+
if query_string.respond_to?(:force_encoding)
|
129
|
+
query_string.force_encoding("ASCII-8BIT")
|
130
|
+
end
|
131
|
+
|
132
|
+
res = Rack::MockRequest.env_for(
|
133
|
+
"/?#{query_string}",
|
134
|
+
"REQUEST_METHOD" => "GET",
|
135
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
136
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
|
137
|
+
req = Rack::Request.new(res[1])
|
138
|
+
req.params['q'].should == [0xe488].pack("U")
|
139
|
+
response_body(res).should == sjis("\xf6\x60")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "softbank のとき" do
|
144
|
+
before(:each) do
|
145
|
+
@res = Rack::MockRequest.env_for(
|
146
|
+
"/",
|
147
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "docomo 絵文字が変換されること" do
|
151
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_cr))).call(@res)[2]
|
152
|
+
response_body(response).should == [0xe04a].pack('U')
|
153
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_utf8))).call(@res)[2]
|
154
|
+
response_body(response).should == [0xe04a].pack('U')
|
155
|
+
|
156
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_docomopoint))).call(@res)[2]
|
157
|
+
response_body(response).should == "[ドコモポイント]"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "au 絵文字が変換されること" do
|
161
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_cr))).call(@res)[2]
|
162
|
+
response_body(response).should == [0xe04a].pack('U')
|
163
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_utf8))).call(@res)[2]
|
164
|
+
response_body(response).should == [0xe04a].pack('U')
|
165
|
+
end
|
166
|
+
|
167
|
+
it "softbank 絵文字が変換されること" do
|
168
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
|
169
|
+
response_body(response).should == [0xe04a].pack('U')
|
170
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
|
171
|
+
response_body(response).should == [0xe04a].pack('U')
|
172
|
+
end
|
173
|
+
|
174
|
+
it "パラメータが変換されること" do
|
175
|
+
query_string = "q=" + URI.encode([0xe04A].pack("U"))
|
176
|
+
|
177
|
+
res = Rack::MockRequest.env_for(
|
178
|
+
"/?#{query_string}",
|
179
|
+
"REQUEST_METHOD" => "GET",
|
180
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
181
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
|
182
|
+
req = Rack::Request.new(res[1])
|
183
|
+
req.params['q'].should == [0xf04a].pack("U")
|
184
|
+
response_body(res).should == [0xe04a].pack('U')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "Vodafone のとき" do
|
189
|
+
before(:each) do
|
190
|
+
@res = Rack::MockRequest.env_for(
|
191
|
+
"/",
|
192
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V705SH/SHJ001/SN000000000000000 Browser/VF-NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
193
|
+
end
|
194
|
+
|
195
|
+
it "softbank 絵文字が変換されること" do
|
196
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
|
197
|
+
response_body(response).should == [0xe04a].pack('U')
|
198
|
+
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
|
199
|
+
response_body(response).should == [0xe04a].pack('U')
|
200
|
+
end
|
201
|
+
|
202
|
+
it "パラメータが変換されること" do
|
203
|
+
query_string = "q=" + URI.encode([0xe04A].pack("U"))
|
204
|
+
|
205
|
+
res = Rack::MockRequest.env_for(
|
206
|
+
"/?#{query_string}",
|
207
|
+
"REQUEST_METHOD" => "GET",
|
208
|
+
'HTTP_USER_AGENT' => "Vodafone/1.0/V705SH/SHJ001/SN000000000000000 Browser/VF-NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
209
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
|
210
|
+
req = Rack::Request.new(res[1])
|
211
|
+
req.params['q'].should == [0xf04a].pack("U")
|
212
|
+
response_body(res).should == [0xe04a].pack('U')
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::Filter do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
include Jpmobile::RackHelper
|
7
|
+
|
8
|
+
context "漢字コード変換" do
|
9
|
+
before(:each) do
|
10
|
+
@utf8 = "ゆーてぃーえふえいとの日本語ですが何か"
|
11
|
+
@sjis = utf8_to_sjis(@utf8)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "docomo のとき" do
|
15
|
+
it "Shift_JIS に変換されること" do
|
16
|
+
res = Rack::MockRequest.env_for(
|
17
|
+
"/",
|
18
|
+
"REQUEST_METHOD" => "GET",
|
19
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
20
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8))).call(res)
|
21
|
+
res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
|
22
|
+
response_body(res) == @sjis
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "au のとき" do
|
27
|
+
it "Shift_JIS に変換されること" do
|
28
|
+
res = Rack::MockRequest.env_for(
|
29
|
+
"/",
|
30
|
+
"REQUEST_METHOD" => "GET",
|
31
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
32
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8))).call(res)
|
33
|
+
res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
|
34
|
+
response_body(res) == @sjis
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "softbank のとき" do
|
39
|
+
it "変換されないこと" do
|
40
|
+
res = Rack::MockRequest.env_for(
|
41
|
+
"/",
|
42
|
+
"REQUEST_METHOD" => "GET",
|
43
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
44
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8))).call(res)
|
45
|
+
res[1]['Content-Type'].should == "text/html"
|
46
|
+
response_body(res) == @utf8
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "絵文字変換" do
|
52
|
+
before(:each) do
|
53
|
+
@utf8 = "ゆーてぃーえふえいとの日本語ですが何か"
|
54
|
+
@emoji_docomo_cr = ""
|
55
|
+
@emoji_au_cr = ""
|
56
|
+
@emoji_softbank_cr = ""
|
57
|
+
@emoji_docomo_utf8 = utf8([0xe64b].pack('U'))
|
58
|
+
@emoji_au_utf8 = utf8([0xe494].pack('U'))
|
59
|
+
@emoji_softbank_utf8 = utf8([0xf244].pack('U'))
|
60
|
+
|
61
|
+
@sjis = utf8_to_sjis(@utf8)
|
62
|
+
@docomo_emoji = sjis("\xf8\xac")
|
63
|
+
@au_emoji = sjis("\xf6\x6c")
|
64
|
+
@softbank_emoji = utf8("\x1b\x24Fd\x0f")
|
65
|
+
end
|
66
|
+
|
67
|
+
context "docomo のとき" do
|
68
|
+
it "数値参照絵文字が変換されること" do
|
69
|
+
res = Rack::MockRequest.env_for(
|
70
|
+
"/",
|
71
|
+
"REQUEST_METHOD" => "GET",
|
72
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
73
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_cr))).call(res)
|
74
|
+
response_body(res) == @sjis + @docomo_emoji
|
75
|
+
end
|
76
|
+
|
77
|
+
it "docomo のUTF-8絵文字が変換されること" do
|
78
|
+
res = Rack::MockRequest.env_for(
|
79
|
+
"/",
|
80
|
+
"REQUEST_METHOD" => "GET",
|
81
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
82
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_utf8))).call(res)
|
83
|
+
response_body(res) == @sjis + @docomo_emoji
|
84
|
+
end
|
85
|
+
|
86
|
+
it "au のUTF-8絵文字が変換されること" do
|
87
|
+
res = Rack::MockRequest.env_for(
|
88
|
+
"/",
|
89
|
+
"REQUEST_METHOD" => "GET",
|
90
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
91
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_utf8))).call(res)
|
92
|
+
response_body(res) == @sjis + @docomo_emoji
|
93
|
+
end
|
94
|
+
|
95
|
+
it "softbank のUTF-8絵文字が変換されること" do
|
96
|
+
res = Rack::MockRequest.env_for(
|
97
|
+
"/",
|
98
|
+
"REQUEST_METHOD" => "GET",
|
99
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
100
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_utf8))).call(res)
|
101
|
+
response_body(res) == @sjis + @docomo_emoji
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "au のとき" do
|
106
|
+
it "数値参照絵文字が変換されること" do
|
107
|
+
res = Rack::MockRequest.env_for(
|
108
|
+
"/",
|
109
|
+
"REQUEST_METHOD" => "GET",
|
110
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
111
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_cr))).call(res)
|
112
|
+
response_body(res) == @sjis + @au_emoji
|
113
|
+
end
|
114
|
+
|
115
|
+
it "docomo のUTF-8絵文字が変換されること" do
|
116
|
+
res = Rack::MockRequest.env_for(
|
117
|
+
"/",
|
118
|
+
"REQUEST_METHOD" => "GET",
|
119
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
120
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_utf8))).call(res)
|
121
|
+
response_body(res) == @sjis + @au_emoji
|
122
|
+
end
|
123
|
+
|
124
|
+
it "au のUTF-8絵文字が変換されること" do
|
125
|
+
res = Rack::MockRequest.env_for(
|
126
|
+
"/",
|
127
|
+
"REQUEST_METHOD" => "GET",
|
128
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
129
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_utf8))).call(res)
|
130
|
+
response_body(res) == @sjis + @au_emoji
|
131
|
+
end
|
132
|
+
|
133
|
+
it "softbank のUTF-8絵文字が変換されること" do
|
134
|
+
res = Rack::MockRequest.env_for(
|
135
|
+
"/",
|
136
|
+
"REQUEST_METHOD" => "GET",
|
137
|
+
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
138
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_utf8))).call(res)
|
139
|
+
response_body(res) == @sjis + @au_emoji
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "softbank のとき" do
|
144
|
+
it "数値参照絵文字が変換されること" do
|
145
|
+
res = Rack::MockRequest.env_for(
|
146
|
+
"/",
|
147
|
+
"REQUEST_METHOD" => "GET",
|
148
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
149
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_cr))).call(res)
|
150
|
+
response_body(res) == @utf8 + @softbank_emoji
|
151
|
+
end
|
152
|
+
|
153
|
+
it "docomo のUTF-8絵文字が変換されること" do
|
154
|
+
res = Rack::MockRequest.env_for(
|
155
|
+
"/",
|
156
|
+
"REQUEST_METHOD" => "GET",
|
157
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
158
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_utf8))).call(res)
|
159
|
+
response_body(res) == @utf8 + @softbank_emoji
|
160
|
+
end
|
161
|
+
|
162
|
+
it "au のUTF-8絵文字が変換されること" do
|
163
|
+
res = Rack::MockRequest.env_for(
|
164
|
+
"/",
|
165
|
+
"REQUEST_METHOD" => "GET",
|
166
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
167
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_utf8))).call(res)
|
168
|
+
response_body(res) == @utf8 + @softbank_emoji
|
169
|
+
end
|
170
|
+
|
171
|
+
it "softbank のUTF-8絵文字が変換されること" do
|
172
|
+
res = Rack::MockRequest.env_for(
|
173
|
+
"/",
|
174
|
+
"REQUEST_METHOD" => "GET",
|
175
|
+
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
176
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_utf8))).call(res)
|
177
|
+
response_body(res) == @utf8 + @softbank_emoji
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::MobileCarrier, "iphone" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
context "端末種別で" do
|
8
|
+
it "iPhone を判別できること" do
|
9
|
+
res = Rack::MockRequest.env_for(
|
10
|
+
'http://jpmobile-rails.org/',
|
11
|
+
'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16')
|
12
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
13
|
+
|
14
|
+
env['rack.jpmobile'].class.should == Jpmobile::Mobile::Iphone
|
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
|
+
|
21
|
+
context "IPアドレス制限で" do
|
22
|
+
it "Softbank 網からのアクセスでも invalid になること" do
|
23
|
+
res = Rack::MockRequest.env_for(
|
24
|
+
'http://jpmobile-rails.org/',
|
25
|
+
'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16',
|
26
|
+
"REMOTE_ADDR"=>"202.179.204.1")
|
27
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
28
|
+
|
29
|
+
env['rack.jpmobile'].valid_ip?.should be_false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
|
3
|
+
|
4
|
+
describe Jpmobile::Rack::MobileCarrier do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
[
|
8
|
+
[ Jpmobile::Mobile::Docomo , 'DoCoMo/2.0 SH902i(c100;TB;W24H12)' ],
|
9
|
+
[ Jpmobile::Mobile::Docomo , 'DoCoMo/1.0/SO506iC/c20/TB/W20H10' ],
|
10
|
+
[ Jpmobile::Mobile::Docomo , 'DoCoMo/2.0 D902i(c100;TB;W23H16;ser999999999999999;icc0000000000000000000f)' ],
|
11
|
+
[ Jpmobile::Mobile::Au , 'KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0' ],
|
12
|
+
[ Jpmobile::Mobile::Au , 'UP.Browser/3.04-KCTA UP.Link/3.4.5.9' ],
|
13
|
+
[ Jpmobile::Mobile::Softbank , 'SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1' ],
|
14
|
+
[ Jpmobile::Mobile::Softbank , 'Semulator' ],
|
15
|
+
[ Jpmobile::Mobile::Vodafone , 'Vodafone/1.0/V903SH/SHJ001/SN000000000000000 Browser/UP.Browser/7.0.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0' ],
|
16
|
+
[ Jpmobile::Mobile::Willcom , 'Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0' ],
|
17
|
+
[ Jpmobile::Mobile::Ddipocket , 'Mozilla/3.0(DDIPOCKET;KYOCERA/AH-K3001V/1.8.2.71.000000/0.1/C100) Opera 7.0'],
|
18
|
+
[ Jpmobile::Mobile::Emobile , 'emobile/1.0.0 (H11T; like Gecko; Wireless) NetFront/3.4' ],
|
19
|
+
[ Jpmobile::Mobile::Iphone , 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16' ],
|
20
|
+
[ Jpmobile::Mobile::Android , 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' ],
|
21
|
+
[ Jpmobile::Mobile::WindowsPhone , 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)' ],
|
22
|
+
].each do |carrier, user_agent|
|
23
|
+
it '#mobile should return #{carrier} when take #{user_agent} as UserAgent' do
|
24
|
+
res = Rack::MockRequest.env_for(
|
25
|
+
'http://jpmobile-rails.org/',
|
26
|
+
'HTTP_USER_AGENT' => user_agent)
|
27
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
28
|
+
env['rack.jpmobile'].class.should == carrier
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "Googlebot のときは rack['rack.jpmobile.carrier'] が nil になること" do
|
33
|
+
res = Rack::MockRequest.env_for(
|
34
|
+
'http://jpmobile-rails.org/',
|
35
|
+
'HTTP_USER_AGENT' => 'Googlebot')
|
36
|
+
env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
|
37
|
+
env['rack.jpmobile'].should be_nil
|
38
|
+
end
|
39
|
+
end
|