jpmobile 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/.gitignore +6 -0
  2. data/{test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE → MIT-LICENSE} +0 -0
  3. data/README.rdoc +16 -6
  4. data/Rakefile +14 -0
  5. data/VERSION.yml +4 -0
  6. data/init.rb +3 -0
  7. data/install.rb +1 -0
  8. data/jpmobile.gemspec +299 -0
  9. data/lib/jpmobile.rb +0 -2
  10. data/lib/jpmobile/emoticon.rb +16 -2
  11. data/lib/jpmobile/emoticon/z_combine.rb +17 -4
  12. data/lib/jpmobile/filter.rb +2 -3
  13. data/lib/jpmobile/mobile/abstract_mobile.rb +6 -0
  14. data/lib/jpmobile/mobile/docomo.rb +24 -1
  15. data/lib/jpmobile/mobile/z_ip_addresses_au.rb +3 -2
  16. data/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +4 -1
  17. data/lib/jpmobile/request_with_mobile.rb +4 -1
  18. data/{test/rails/rails_root/vendor/plugins/jpmobile/spec → spec}/spec.opts +0 -0
  19. data/spec/spec_helper.rb +36 -0
  20. data/spec/unit/detect_by_email_spec.rb +31 -0
  21. data/{test/rails/rails_root/vendor/plugins/jpmobile/spec → spec}/unit/detect_by_ua_spec.rb +11 -13
  22. data/spec/unit/is_carrier_spec.rb +93 -0
  23. data/spec/unit/spec_helper.rb +5 -0
  24. data/spec/unit/util_spec.rb +30 -0
  25. data/spec/unit/valid_ip_spec.rb +60 -0
  26. data/{test/rails/rails_root/vendor/plugins/jpmobile/tasks → tasks}/jpmobile_tasks.rake +3 -3
  27. data/test/legacy/autoload_test.rb +2 -1
  28. data/test/legacy/docomo_test.rb +39 -0
  29. data/test/legacy/emoticon_functional_test.rb +21 -19
  30. data/test/legacy/emoticon_test.rb +12 -12
  31. data/test/legacy/filter_test.rb +10 -8
  32. data/test/legacy/helper.rb +32 -3
  33. data/test/legacy/softbank_test.rb +2 -0
  34. data/test/rails/.gitignore +1 -0
  35. data/test/rails/overrides/app/controllers/filter_controller.rb +10 -0
  36. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +2 -0
  37. data/test/rails/overrides/spec/controllers/docomo_spec.rb +2 -0
  38. data/test/rails/overrides/spec/controllers/emobile_spec.rb +2 -0
  39. data/test/rails/overrides/spec/controllers/filter_spec.rb +8 -7
  40. data/test/rails/overrides/spec/controllers/pc_spec.rb +2 -0
  41. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +2 -0
  42. data/test/rails/overrides/spec/controllers/template_path_spec.rb +2 -0
  43. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +1 -0
  44. data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -0
  45. data/test/rails/overrides/spec/spec_helper.rb +15 -0
  46. data/test/rails/rails_root/app/controllers/filter_controller.rb +0 -23
  47. data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +1 -1
  48. data/test/rails/rails_root/app/controllers/template_path_controller.rb +3 -0
  49. data/test/rails/rails_root/app/helpers/application_helper.rb +0 -1
  50. data/test/rails/rails_root/config/boot.rb +13 -110
  51. data/test/rails/rails_root/config/environment.rb +4 -41
  52. data/test/rails/rails_root/config/environments/development.rb +22 -13
  53. data/test/rails/rails_root/config/environments/production.rb +41 -20
  54. data/test/rails/rails_root/config/environments/test.rb +35 -28
  55. data/test/rails/rails_root/config/initializers/backtrace_silencers.rb +2 -2
  56. data/test/rails/rails_root/config/initializers/inflections.rb +1 -1
  57. data/test/rails/rails_root/config/initializers/session_store.rb +2 -15
  58. data/test/rails/rails_root/config/routes.rb +6 -42
  59. data/test/rails/rails_root/db/schema.rb +24 -7
  60. data/test/rails/rails_root/db/seeds.rb +2 -2
  61. data/test/rails/rails_root/spec/helpers/helpers_spec.rb +4 -2
  62. data/test/rails/rails_root/spec/spec_helper.rb +19 -35
  63. data/test/rails/rails_root/test/performance/browsing_test.rb +2 -2
  64. data/test/rails/rails_root/test/test_helper.rb +2 -27
  65. data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +1 -1
  66. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +39 -25
  67. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +2 -1
  68. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +3 -4
  69. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +24 -8
  70. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +10 -9
  71. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +17 -4
  72. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +43 -136
  73. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +5 -18
  74. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +24 -16
  75. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +42 -85
  76. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +25 -2
  77. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +28 -3
  78. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +29 -26
  79. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +60 -11
  80. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +16 -41
  81. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +1 -10
  82. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +3 -2
  83. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +4 -1
  84. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +4 -3
  85. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +14 -13
  86. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +52 -35
  87. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +68 -0
  88. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +3 -2
  89. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +21 -27
  90. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +56 -84
  91. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +1 -2
  92. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +8 -2
  93. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +43 -52
  94. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/disabled_update_display_info_docomo.rb +0 -0
  95. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +0 -0
  96. data/tools/emoji/genregexp.rb +47 -0
  97. metadata +348 -253
  98. data/test/rails/rails_root/README +0 -243
  99. data/test/rails/rails_root/Rakefile +0 -10
  100. data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +0 -13
  101. data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +0 -28
  102. data/test/rails/rails_root/app/views/filter/index.html.erb +0 -0
  103. data/test/rails/rails_root/app/views/hankaku_filter/index.html.erb +0 -0
  104. data/test/rails/rails_root/app/views/template_path/_partial.html.erb +0 -1
  105. data/test/rails/rails_root/app/views/template_path/_partial_mobile.html.erb +0 -1
  106. data/test/rails/rails_root/app/views/template_path/_partial_mobile_docomo.html.erb +0 -1
  107. data/test/rails/rails_root/app/views/template_path/index.html.erb +0 -1
  108. data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +0 -1
  109. data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +0 -1
  110. data/test/rails/rails_root/app/views/template_path/partial.html.erb +0 -2
  111. data/test/rails/rails_root/config/database.yml +0 -22
  112. data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +0 -21
  113. data/test/rails/rails_root/config/locales/en.yml +0 -5
  114. data/test/rails/rails_root/db/development.sqlite3 +0 -0
  115. data/test/rails/rails_root/db/test.sqlite3 +0 -0
  116. data/test/rails/rails_root/doc/README_FOR_APP +0 -2
  117. data/test/rails/rails_root/lib/tasks/rspec.rake +0 -165
  118. data/test/rails/rails_root/log/development.log +0 -38
  119. data/test/rails/rails_root/log/production.log +0 -0
  120. data/test/rails/rails_root/log/server.log +0 -0
  121. data/test/rails/rails_root/log/test.log +0 -451
  122. data/test/rails/rails_root/public/404.html +0 -30
  123. data/test/rails/rails_root/public/422.html +0 -30
  124. data/test/rails/rails_root/public/500.html +0 -30
  125. data/test/rails/rails_root/public/favicon.ico +0 -0
  126. data/test/rails/rails_root/public/images/rails.png +0 -0
  127. data/test/rails/rails_root/public/index.html +0 -275
  128. data/test/rails/rails_root/public/javascripts/application.js +0 -2
  129. data/test/rails/rails_root/public/javascripts/controls.js +0 -963
  130. data/test/rails/rails_root/public/javascripts/dragdrop.js +0 -973
  131. data/test/rails/rails_root/public/javascripts/effects.js +0 -1128
  132. data/test/rails/rails_root/public/javascripts/prototype.js +0 -4320
  133. data/test/rails/rails_root/public/robots.txt +0 -5
  134. data/test/rails/rails_root/script/about +0 -4
  135. data/test/rails/rails_root/script/console +0 -3
  136. data/test/rails/rails_root/script/dbconsole +0 -3
  137. data/test/rails/rails_root/script/destroy +0 -3
  138. data/test/rails/rails_root/script/generate +0 -3
  139. data/test/rails/rails_root/script/performance/benchmarker +0 -3
  140. data/test/rails/rails_root/script/performance/profiler +0 -3
  141. data/test/rails/rails_root/script/plugin +0 -3
  142. data/test/rails/rails_root/script/runner +0 -3
  143. data/test/rails/rails_root/script/server +0 -3
  144. data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +0 -77
  145. data/test/rails/rails_root/spec/controllers/docomo_spec.rb +0 -28
  146. data/test/rails/rails_root/spec/controllers/emobile_spec.rb +0 -35
  147. data/test/rails/rails_root/spec/controllers/filter_spec.rb +0 -157
  148. data/test/rails/rails_root/spec/controllers/pc_spec.rb +0 -11
  149. data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +0 -40
  150. data/test/rails/rails_root/spec/controllers/template_path_spec.rb +0 -115
  151. data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +0 -99
  152. data/test/rails/rails_root/spec/rcov.opts +0 -2
  153. data/test/rails/rails_root/spec/rspec.rake +0 -165
  154. data/test/rails/rails_root/spec/spec.opts +0 -4
  155. data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +0 -7
  156. data/test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc +0 -239
  157. data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +0 -116
  158. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +0 -5
  159. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/auth.rb +0 -55
  160. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/combined_logger.rb +0 -54
  161. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/request.rb +0 -7
  162. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/trans_sid.rb +0 -14
  163. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +0 -9
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require File.dirname(__FILE__)+'/helper'
2
3
 
3
4
  class DocomoTest < Test::Unit::TestCase
@@ -145,4 +146,42 @@ class DocomoTest < Test::Unit::TestCase
145
146
  assert_equal(262144, req.mobile.display.colors)
146
147
  end
147
148
  end
149
+
150
+ # i-modeブラウザバージョン判定
151
+ def test_docomo_imode_browser_version
152
+ reqs = request_with_ua("DoCoMo/2.0 SH902i(c100;TB;W24H12)")
153
+ reqs << request_with_ua("DoCoMo/1.0/F505iGPS/c20/TB/W20H10")
154
+ reqs.flatten.each do |req|
155
+ assert_equal('1.0', req.mobile.imode_browser_version)
156
+ end
157
+
158
+ reqs = request_with_ua("DoCoMo/2.0 P09A3(c500;TB;W20H12)")
159
+ reqs << request_with_ua("DoCoMo/2.0 P07A3(c500;TB;W24H15)")
160
+ reqs.flatten.each do |req|
161
+ assert_equal('2.0', req.mobile.imode_browser_version)
162
+ end
163
+
164
+ reqs = request_with_ua("DoCoMo/2.0 L01B(c500;TB;W40H10)")
165
+ reqs.flatten.each do |req|
166
+ assert_equal('2.0LE', req.mobile.imode_browser_version)
167
+ end
168
+ end
169
+
170
+ # cookie support
171
+ def test_docomo_imode_browser_version
172
+ # i-modeブラウザ1.0 == false
173
+ reqs = request_with_ua("DoCoMo/2.0 SH902i(c100;TB;W24H12)")
174
+ reqs << request_with_ua("DoCoMo/1.0/F505iGPS/c20/TB/W20H10")
175
+ reqs.flatten.each do |req|
176
+ assert(!req.mobile.supports_cookie?)
177
+ end
178
+
179
+ # i-modeブラウザ2.0 & 2.0LE == true
180
+ reqs = request_with_ua("DoCoMo/2.0 P09A3(c500;TB;W20H12)")
181
+ reqs << request_with_ua("DoCoMo/2.0 P07A3(c500;TB;W24H15)")
182
+ reqs << request_with_ua("DoCoMo/2.0 L01B(c500;TB;W40H10)")
183
+ reqs.flatten.each do |req|
184
+ assert(req.mobile.supports_cookie?)
185
+ end
186
+ end
148
187
  end
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__)+'/helper'
2
4
 
3
5
  class EmoticonTestController < ActionController::Base
@@ -46,26 +48,26 @@ class EmoticonFunctionalTest < ActionController::TestCase
46
48
  # DoCoMo携帯
47
49
  user_agent "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
48
50
  get :docomo_cr
49
- assert_equal "\xf8\x9f", @response.body
51
+ assert_equal sjis("\xf8\x9f"), @response.body
50
52
  get :docomo_utf8
51
- assert_equal "\xf8\x9f", @response.body
52
- get :query, :q=>"\xf8\x9f"
53
+ assert_equal sjis("\xf8\x9f"), @response.body
54
+ get :query, :q=>sjis("\xf8\x9f")
53
55
  assert_equal "\xee\x98\xbe", assigns["q"]
54
- assert_equal "\xf8\x9f", @response.body
56
+ assert_equal sjis("\xf8\x9f"), @response.body
55
57
 
56
58
  get :docomo_docomopoint
57
- assert_equal "\xf9\x79", @response.body
59
+ assert_equal sjis("\xf9\x79"), @response.body
58
60
  end
59
61
 
60
62
  def test_docomo_from_au
61
63
  # Au携帯電話での閲覧
62
64
  user_agent "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
63
65
  get :docomo_cr
64
- assert_equal "\xf6\x60", @response.body
66
+ assert_equal sjis("\xf6\x60"), @response.body
65
67
  get :docomo_utf8
66
- assert_equal "\xf6\x60", @response.body
68
+ assert_equal sjis("\xf6\x60"), @response.body
67
69
  get :docomo_docomopoint
68
- assert_equal "[ドコモポイント]".tosjis, @response.body
70
+ assert_equal to_sjis("[ドコモポイント]"), @response.body
69
71
  end
70
72
 
71
73
  def test_docomo_from_softbank
@@ -88,7 +90,7 @@ class EmoticonFunctionalTest < ActionController::TestCase
88
90
  assert_equal "\e$Gj\x0f", @response.body
89
91
  get :docomo_docomopoint
90
92
  assert_equal "Shift_JIS", @response.charset
91
- assert_equal "[ドコモポイント]".tosjis, @response.body
93
+ assert_equal to_sjis("[ドコモポイント]"), @response.body
92
94
  end
93
95
 
94
96
  def test_au_from_pc
@@ -103,21 +105,21 @@ class EmoticonFunctionalTest < ActionController::TestCase
103
105
  # Au
104
106
  user_agent "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
105
107
  get :au_cr
106
- assert_equal "\xf6\x60", @response.body
108
+ assert_equal sjis("\xf6\x60"), @response.body
107
109
  get :au_utf8
108
- assert_equal "\xf6\x60", @response.body
109
- get :query, :q=>"\xf6\x60"
110
+ assert_equal sjis("\xf6\x60"), @response.body
111
+ get :query, :q=>sjis("\xf6\x60")
110
112
  assert_equal [0xe488].pack("U"), assigns["q"]
111
- assert_equal "\xf6\x60", @response.body
113
+ assert_equal sjis("\xf6\x60"), @response.body
112
114
  end
113
115
 
114
116
  def test_au_from_docomo
115
117
  # DoCoMo携帯電話での閲覧
116
118
  user_agent "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
117
119
  get :au_cr
118
- assert_equal "\xf8\x9f", @response.body
120
+ assert_equal sjis("\xf8\x9f"), @response.body
119
121
  get :au_utf8
120
- assert_equal "\xf8\x9f", @response.body
122
+ assert_equal sjis("\xf8\x9f"), @response.body
121
123
  end
122
124
 
123
125
  def test_au_from_softbank
@@ -177,17 +179,17 @@ class EmoticonFunctionalTest < ActionController::TestCase
177
179
  # DoCoMo携帯電話での閲覧
178
180
  user_agent "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
179
181
  get :softbank_cr
180
- assert_equal "\xf8\x9f", @response.body
182
+ assert_equal sjis("\xf8\x9f"), @response.body
181
183
  get :softbank_utf8
182
- assert_equal "\xf8\x9f", @response.body
184
+ assert_equal sjis("\xf8\x9f"), @response.body
183
185
  end
184
186
 
185
187
  def test_softbank_from_au
186
188
  # Au携帯電話での閲覧
187
189
  user_agent "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
188
190
  get :softbank_cr
189
- assert_equal "\xf6\x60", @response.body
191
+ assert_equal sjis("\xf6\x60"), @response.body
190
192
  get :softbank_utf8
191
- assert_equal "\xf6\x60", @response.body
193
+ assert_equal sjis("\xf6\x60"), @response.body
192
194
  end
193
195
  end
@@ -2,34 +2,34 @@ require File.dirname(__FILE__)+'/helper'
2
2
 
3
3
  class DocomoEmoticonTest < Test::Unit::TestCase
4
4
  def test_external_unicodecr_docomo
5
- assert_equal "&#xe63e;", Jpmobile::Emoticon::external_to_unicodecr_docomo("\xf8\x9f")
5
+ assert_equal "&#xe63e;", Jpmobile::Emoticon::external_to_unicodecr_docomo(sjis("\xf8\x9f"))
6
6
  end
7
7
  def test_unicodecr_external_docomo
8
- assert_equal "\xf8\x9f", Jpmobile::Emoticon::unicodecr_to_external("&#xe63e;")
8
+ assert_equal sjis("\xf8\x9f"), Jpmobile::Emoticon::unicodecr_to_external("&#xe63e;")
9
9
  end
10
10
  def test_unicodecr_external_docomo_for_string
11
- assert_equal "\xf8\x9f\xf8\xa0", Jpmobile::Emoticon::unicodecr_to_external("&#xE48E;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO, true)
11
+ assert_equal sjis("\xf8\x9f\xf8\xa0"), Jpmobile::Emoticon::unicodecr_to_external("&#xE48E;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO, true)
12
12
  end
13
13
  def test_unicodecr_utf8_docomo
14
- assert_equal "\356\230\276", Jpmobile::Emoticon::unicodecr_to_utf8("&#xe63e;")
14
+ assert_equal utf8("\356\230\276"), Jpmobile::Emoticon::unicodecr_to_utf8("&#xe63e;")
15
15
  end
16
16
  def test_utf8_unicodecr_docomo
17
- assert_equal "&#xe63e;", Jpmobile::Emoticon::utf8_to_unicodecr("\356\230\276")
17
+ assert_equal "&#xe63e;", Jpmobile::Emoticon::utf8_to_unicodecr(utf8("\356\230\276"))
18
18
  end
19
19
  end
20
20
 
21
21
  class AuEmoticonTest < Test::Unit::TestCase
22
22
  def test_au_external_unicodecr
23
- assert_equal "&#xe481;", Jpmobile::Emoticon::external_to_unicodecr_au("\xf6\x59")
23
+ assert_equal "&#xe481;", Jpmobile::Emoticon::external_to_unicodecr_au(sjis("\xf6\x59"))
24
24
  end
25
25
  def test_au_unicodecr_external
26
- assert_equal "\xf6\x59", Jpmobile::Emoticon::unicodecr_to_external("&#xe481;")
26
+ assert_equal sjis("\xf6\x59"), Jpmobile::Emoticon::unicodecr_to_external("&#xe481;")
27
27
  end
28
28
  def test_au_unicodecr_utf8
29
- assert_equal "\356\222\201", Jpmobile::Emoticon::unicodecr_to_utf8("&#xe481;")
29
+ assert_equal utf8("\356\222\201"), Jpmobile::Emoticon::unicodecr_to_utf8("&#xe481;")
30
30
  end
31
31
  def test_au_utf8_unicodecr
32
- assert_equal "&#xe481;", Jpmobile::Emoticon::utf8_to_unicodecr("\356\222\201")
32
+ assert_equal "&#xe481;", Jpmobile::Emoticon::utf8_to_unicodecr(utf8("\356\222\201"))
33
33
  end
34
34
  end
35
35
 
@@ -47,10 +47,10 @@ class SoftbankEmoticonTest < Test::Unit::TestCase
47
47
  assert_equal "\x1b$G!\x0f", Jpmobile::Emoticon::unicodecr_to_external("&#xf001;")
48
48
  end
49
49
  def test_softbank_cr_utf8
50
- assert_equal "\xef\x80\x81", Jpmobile::Emoticon::unicodecr_to_utf8("&#xf001;")
50
+ assert_equal utf8("\xef\x80\x81"), Jpmobile::Emoticon::unicodecr_to_utf8("&#xf001;")
51
51
  end
52
52
  def test_softbank_utf8_cr
53
- assert_equal "&#xf001;", Jpmobile::Emoticon::utf8_to_unicodecr("\xef\x80\x81")
53
+ assert_equal "&#xf001;", Jpmobile::Emoticon::utf8_to_unicodecr(utf8("\xef\x80\x81"))
54
54
  end
55
55
  def test_unicodecr_external_softbank_for_string
56
56
  assert_equal "\x1b$Gj\x0f\x1b$Gi\x0f", Jpmobile::Emoticon::unicodecr_to_external("&#xE48E;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK, true)
@@ -59,6 +59,6 @@ end
59
59
 
60
60
  class KoukaiEmoticonTest < Test::Unit::TestCase
61
61
  def test_koukai_sjis
62
- assert_equal "\x8c\xf6\x8a\x4a", Jpmobile::Emoticon::external_to_unicodecr_docomo("\x8c\xf6\x8a\x4a")
62
+ assert_equal sjis("\x8c\xf6\x8a\x4a"), Jpmobile::Emoticon::external_to_unicodecr_docomo(sjis("\x8c\xf6\x8a\x4a"))
63
63
  end
64
64
  end
@@ -1,17 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__)+'/helper'
2
4
 
3
5
  class FilterTest < Test::Unit::TestCase
4
6
  def setup
5
- @aiu_sjis = "\202\240\202\242\202\244" # あいう
6
- @aiu_utf8 = "\343\201\202\343\201\204\343\201\206" # あいう
7
+ @aiu_sjis = sjis("\202\240\202\242\202\244") # あいう
8
+ @aiu_utf8 = utf8("\343\201\202\343\201\204\343\201\206") # あいう
7
9
 
8
- @aiu_zhz = "\343\201\202\357\275\262\343\202\246" # あイウ (イ半角), UTF-8
9
- @aiu_zzz = "\343\201\202\343\202\244\343\202\246" # あイウ, UTF-8
10
- @aiu_zhh = "\343\201\202\357\275\262\357\275\263" # あイウ (イウ半角), UTF-8
10
+ @aiu_zhz = utf8("\343\201\202\357\275\262\343\202\246") # あイウ (イ半角), UTF-8
11
+ @aiu_zzz = utf8("\343\201\202\343\202\244\343\202\246") # あイウ, UTF-8
12
+ @aiu_zhh = utf8("\343\201\202\357\275\262\357\275\263") # あイウ (イウ半角), UTF-8
11
13
 
12
- @abracadabra_z_utf8 = "\343\202\242\343\203\226\343\203\251\343\202\253\343\203\200\343\203\226\343\203\251" # アブラカダブラ, UTF-8
13
- @abracadabra_h_utf8 = "\357\275\261\357\276\214\357\276\236\357\276\227\357\275\266\357\276\200\357\276\236\357\276\214\357\276\236\357\276\227" # アブラカダブラ(半角), UTF-8
14
- @abracadabra_z_sjis = "\203A\203u\203\211\203J\203_\203u\203\211" # アブラカダブラ, Shift_JIS
14
+ @abracadabra_z_utf8 = utf8("\343\202\242\343\203\226\343\203\251\343\202\253\343\203\200\343\203\226\343\203\251") # アブラカダブラ, UTF-8
15
+ @abracadabra_h_utf8 = utf8("\357\275\261\357\276\214\357\276\236\357\276\227\357\275\266\357\276\200\357\276\236\357\276\214\357\276\236\357\276\227") # アブラカダブラ(半角), UTF-8
16
+ @abracadabra_z_sjis = sjis("\203A\203u\203\211\203J\203_\203u\203\211") # アブラカダブラ, Shift_JIS
15
17
  end
16
18
  def test_filter_sjis
17
19
  filter = Jpmobile::Filter::Sjis.new
@@ -1,5 +1,13 @@
1
- require 'test/unit'
1
+ # -*- coding: utf-8 -*-
2
+
2
3
  require 'rubygems'
4
+ begin
5
+ gem 'test-unit', '= 1.2.3'
6
+ rescue Gem::LoadError
7
+ end
8
+ require 'test/unit'
9
+ action_pack_version = ENV['RAILS_VERSION'] || '2.3.0'
10
+ gem 'actionpack', "~> #{action_pack_version}"
3
11
  require 'action_controller'
4
12
  require 'rack'
5
13
 
@@ -7,8 +15,10 @@ RAILS_ENV = "test"
7
15
  require File.dirname(__FILE__)+'/../../lib/jpmobile'
8
16
 
9
17
  # ActionPackのTestのためのrequire
10
- action_pack_full_path = Gem.cache.search('actionpack').sort_by { |g| g.version.version }.last
11
- require File.join(action_pack_full_path.full_gem_path,'test/abstract_unit')
18
+ action_pack_gem = Gem.cache.find_name('actionpack').find do |gem|
19
+ gem.version.version >= action_pack_version
20
+ end
21
+ require File.join(action_pack_gem.full_gem_path,'test/abstract_unit')
12
22
 
13
23
  class FakeCgi < CGI
14
24
  attr_accessor :stdinput, :stdoutput, :env_table
@@ -46,5 +56,24 @@ module Jpmobile::TestHelper
46
56
  @request.host = "www.example.jp"
47
57
  @request.session.session_id = "mysessionid"
48
58
  end
59
+ def sjis(ascii_8bit)
60
+ if ascii_8bit.respond_to?(:force_encoding)
61
+ ascii_8bit.force_encoding("Shift_JIS")
62
+ end
63
+ ascii_8bit
64
+ end
65
+ def utf8(ascii_8bit)
66
+ if ascii_8bit.respond_to?(:force_encoding)
67
+ ascii_8bit.force_encoding("utf-8")
68
+ end
69
+ ascii_8bit
70
+ end
71
+ def to_sjis(utf8)
72
+ if utf8.respond_to?(:encode)
73
+ utf8.encode("Shift_JIS")
74
+ else
75
+ utf8.tosjis
76
+ end
77
+ end
49
78
  end
50
79
  Test::Unit::TestCase.class_eval{ include Jpmobile::TestHelper }
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__)+'/helper'
2
4
 
3
5
  class SoftbankTest < Test::Unit::TestCase
@@ -0,0 +1 @@
1
+ rails_root
@@ -24,4 +24,14 @@ end
24
24
 
25
25
  class HankakuFilterController < FilterControllerBase
26
26
  mobile_filter :hankaku => true
27
+
28
+ around_filter :freeze_response_body
29
+
30
+ private
31
+ def freeze_response_body
32
+ yield
33
+ if response.body.respond_to?(:freeze)
34
+ response.body.freeze
35
+ end
36
+ end
27
37
  end
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe "docomo_guid が起動しないとき", :shared => true do
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe "DoCoMo SH902i からのアクセス" do
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe "H11T モバイルブラウザからのアクセス", :behaviour_type=>:controller do
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require File.dirname(__FILE__) + '/../spec_helper'
3
4
 
4
5
  describe "文字コードフィルタが動作しているとき", :shared => true do
@@ -16,20 +17,20 @@ end
16
17
  describe "Shift_JISで通信する端末との通信", :shared => true do
17
18
  it "はShift_JISで携帯に送出されること" do
18
19
  get :abracadabra_utf8
19
- response.body.should == "アブラカダブラ".tosjis
20
+ response.body.should == to_sjis("アブラカダブラ")
20
21
  response.charset.should == "Shift_JIS"
21
22
  end
22
23
  it "はxhtmlでもShift_JISで携帯に送出されること" do
23
24
  get :abracadabra_xhtml_utf8
24
- response.body.should == "アブラカダブラ".tosjis
25
+ response.body.should == to_sjis("アブラカダブラ")
25
26
  response.charset.should == "Shift_JIS"
26
27
  end
27
28
  it "はShift_JISで渡されたパラメタがparamsにUTF-8に変換されて格納されること" do
28
- get :index, :q => "アブラカダブラ".tosjis
29
+ get :index, :q => to_sjis("アブラカダブラ")
29
30
  assigns[:q].should == "アブラカダブラ"
30
31
  end
31
32
  it "は半角カナのparamsを変換しないこと" do
32
- get :index, :q => "\261\314\336\327\266\300\336\314\336\327" # アブラカダブラ半角,SJIS
33
+ get :index, :q => sjis("\261\314\336\327\266\300\336\314\336\327") # アブラカダブラ半角,SJIS
33
34
  assigns[:q].should == "アブラカダブラ"
34
35
  end
35
36
  it_should_behave_like "文字コードフィルタが動作しているとき"
@@ -60,15 +61,15 @@ end
60
61
  describe "Shift_JISで通信する端末との通信(半角変換付き)", :shared => true do
61
62
  it "は半角に変換されShift_JISで携帯に送出されること" do
62
63
  get :abracadabra_utf8
63
- response.body.should == "\261\314\336\327\266\300\336\314\336\327" # アブラカダブラ半角,SJIS
64
+ response.body.should == sjis("\261\314\336\327\266\300\336\314\336\327") # アブラカダブラ半角,SJIS
64
65
  response.charset.should == "Shift_JIS"
65
66
  end
66
67
  it "はShift_JISで渡されたパラメタがparamsにUTF-8に変換されて格納されること" do
67
- get :index, :q => "アブラカダブラ".tosjis
68
+ get :index, :q => to_sjis("アブラカダブラ")
68
69
  assigns[:q].should == "アブラカダブラ"
69
70
  end
70
71
  it "は半角Shift_JISで渡されたパラメタがparamsに全角UTF-8に変換されて格納されること" do
71
- get :index, :q => "\261\314\336\327\266\300\336\314\336\327" # アブラカダブラ半角,SJIS
72
+ get :index, :q => sjis("\261\314\336\327\266\300\336\314\336\327") # アブラカダブラ半角,SJIS
72
73
  assigns[:q].should == "アブラカダブラ"
73
74
  end
74
75
  it_should_behave_like "文字コードフィルタが動作しているとき"
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe "PCからのアクセスの場合", :behaviour_type=>:controller do
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe "携帯電話からのアクセス", :shared => true do
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require File.dirname(__FILE__) + '/../spec_helper'
3
4
 
4
5
  describe "trans_sid が起動しないとき", :shared => true do
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  describe Jpmobile::Helpers do
@@ -45,3 +45,18 @@ Spec::Runner.configure do |config|
45
45
  #
46
46
  # For more information take a look at Spec::Runner::Configuration and Spec::Runner
47
47
  end
48
+
49
+ def sjis(ascii_8bit)
50
+ if ascii_8bit.respond_to?(:force_encoding)
51
+ ascii_8bit.force_encoding("Shift_JIS")
52
+ end
53
+ ascii_8bit
54
+ end
55
+
56
+ def to_sjis(utf8)
57
+ if utf8.respond_to?(:encode)
58
+ utf8.encode("Shift_JIS")
59
+ else
60
+ utf8.tosjis
61
+ end
62
+ end