jpmobile 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/README.rdoc +227 -0
  2. data/Rakefile +6 -13
  3. data/lib/jpmobile/docomo_guid.rb +42 -0
  4. data/lib/jpmobile/filter.rb +1 -1
  5. data/lib/jpmobile/helpers.rb +2 -1
  6. data/lib/jpmobile/hook_action_controller.rb +12 -0
  7. data/lib/jpmobile/hook_action_view.rb +82 -72
  8. data/lib/jpmobile/{hook_abstract_request.rb → hook_request.rb} +1 -1
  9. data/lib/jpmobile/mobile/au.rb +9 -3
  10. data/lib/jpmobile/mobile/z_display_info_docomo.rb +10 -2
  11. data/lib/jpmobile/mobile/z_ip_addresses_au.rb +1 -26
  12. data/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +2 -4
  13. data/lib/jpmobile/rack/auth.rb +55 -0
  14. data/lib/jpmobile/rack/combined_logger.rb +54 -0
  15. data/lib/jpmobile/rack/request.rb +7 -0
  16. data/lib/jpmobile/rack/trans_sid.rb +14 -0
  17. data/lib/jpmobile/trans_sid.rb +70 -62
  18. data/lib/jpmobile/version.rb +1 -1
  19. data/test/{au_test.rb → legacy/au_test.rb} +0 -0
  20. data/test/{autoload_test.rb → legacy/autoload_test.rb} +0 -0
  21. data/test/{docomo_test.rb → legacy/docomo_test.rb} +0 -0
  22. data/test/{emoticon_functional_test.rb → legacy/emoticon_functional_test.rb} +1 -1
  23. data/test/{emoticon_test.rb → legacy/emoticon_test.rb} +0 -0
  24. data/test/{filter_test.rb → legacy/filter_test.rb} +0 -0
  25. data/test/{helper.rb → legacy/helper.rb} +4 -5
  26. data/test/{helpers_test.rb → legacy/helpers_test.rb} +1 -1
  27. data/test/{softbank_test.rb → legacy/softbank_test.rb} +0 -0
  28. data/test/{willcom_test.rb → legacy/willcom_test.rb} +0 -0
  29. data/test/rails/overrides/app/controllers/application.rb +5 -0
  30. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +13 -0
  31. data/test/rails/overrides/app/controllers/filter_controller.rb +26 -0
  32. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +5 -0
  33. data/test/rails/overrides/app/controllers/template_path_controller.rb +6 -0
  34. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +28 -0
  35. data/test/rails/overrides/app/views/filter/index.html.erb +0 -0
  36. data/test/rails/overrides/app/views/hankaku_filter/index.html.erb +0 -0
  37. data/test/rails/overrides/app/views/template_path/_partial.html.erb +1 -0
  38. data/test/rails/overrides/app/views/template_path/_partial_mobile.html.erb +1 -0
  39. data/test/rails/overrides/app/views/template_path/_partial_mobile_docomo.html.erb +1 -0
  40. data/test/rails/overrides/app/views/template_path/index.html.erb +1 -0
  41. data/test/rails/overrides/app/views/template_path/index_mobile.html.erb +1 -0
  42. data/test/rails/overrides/app/views/template_path/index_mobile_docomo.html.erb +1 -0
  43. data/test/rails/overrides/app/views/template_path/partial.html.erb +2 -0
  44. data/test/rails/overrides/lib/tasks/rspec.rake +165 -0
  45. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +77 -0
  46. data/test/rails/overrides/spec/controllers/docomo_spec.rb +28 -0
  47. data/test/rails/overrides/spec/controllers/emobile_spec.rb +35 -0
  48. data/test/rails/overrides/spec/controllers/filter_spec.rb +157 -0
  49. data/test/rails/overrides/spec/controllers/pc_spec.rb +11 -0
  50. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +40 -0
  51. data/test/rails/overrides/spec/controllers/template_path_spec.rb +115 -0
  52. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +98 -0
  53. data/test/rails/overrides/spec/helpers/helpers_spec.rb +13 -0
  54. data/test/rails/overrides/spec/rcov.opts +2 -0
  55. data/test/rails/overrides/spec/rspec.rake +165 -0
  56. data/test/rails/overrides/spec/spec.opts +4 -0
  57. data/test/rails/overrides/spec/spec_helper.rb +47 -0
  58. data/test/rails/rails_root/README +256 -0
  59. data/test/rails/rails_root/Rakefile +10 -0
  60. data/test/rails/rails_root/app/controllers/application.rb +5 -0
  61. data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +13 -0
  62. data/test/rails/rails_root/app/controllers/filter_controller.rb +26 -0
  63. data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +5 -0
  64. data/test/rails/rails_root/app/controllers/template_path_controller.rb +6 -0
  65. data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +26 -0
  66. data/test/rails/rails_root/app/helpers/application_helper.rb +3 -0
  67. data/test/rails/rails_root/app/views/template_path/index.html.erb +1 -0
  68. data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +1 -0
  69. data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +1 -0
  70. data/test/rails/rails_root/config/boot.rb +109 -0
  71. data/test/rails/rails_root/config/database.yml +22 -0
  72. data/test/rails/rails_root/config/environment.rb +75 -0
  73. data/test/rails/rails_root/config/environments/development.rb +17 -0
  74. data/test/rails/rails_root/config/environments/production.rb +24 -0
  75. data/test/rails/rails_root/config/environments/test.rb +22 -0
  76. data/test/rails/rails_root/config/initializers/inflections.rb +10 -0
  77. data/test/rails/rails_root/config/initializers/mime_types.rb +5 -0
  78. data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +17 -0
  79. data/test/rails/rails_root/config/locales/en.yml +5 -0
  80. data/test/rails/rails_root/config/routes.rb +43 -0
  81. data/test/rails/rails_root/db/development.sqlite3 +0 -0
  82. data/test/rails/rails_root/db/schema.rb +14 -0
  83. data/test/rails/rails_root/db/test.sqlite3 +0 -0
  84. data/test/rails/rails_root/doc/README_FOR_APP +5 -0
  85. data/test/rails/rails_root/lib/tasks/rspec.rake +165 -0
  86. data/test/rails/rails_root/log/development.log +38 -0
  87. data/test/rails/rails_root/log/production.log +0 -0
  88. data/test/rails/rails_root/log/server.log +0 -0
  89. data/test/rails/rails_root/log/test.log +401 -0
  90. data/test/rails/rails_root/public/404.html +30 -0
  91. data/test/rails/rails_root/public/422.html +30 -0
  92. data/test/rails/rails_root/public/500.html +33 -0
  93. data/test/rails/rails_root/public/dispatch.cgi +10 -0
  94. data/test/rails/rails_root/public/dispatch.fcgi +24 -0
  95. data/test/rails/rails_root/public/dispatch.rb +10 -0
  96. data/test/rails/rails_root/public/favicon.ico +0 -0
  97. data/test/rails/rails_root/public/images/rails.png +0 -0
  98. data/test/rails/rails_root/public/index.html +274 -0
  99. data/test/rails/rails_root/public/javascripts/application.js +2 -0
  100. data/test/rails/rails_root/public/javascripts/controls.js +963 -0
  101. data/test/rails/rails_root/public/javascripts/dragdrop.js +973 -0
  102. data/test/rails/rails_root/public/javascripts/effects.js +1128 -0
  103. data/test/rails/rails_root/public/javascripts/prototype.js +4320 -0
  104. data/test/rails/rails_root/public/robots.txt +5 -0
  105. data/test/rails/rails_root/script/about +4 -0
  106. data/test/rails/rails_root/script/console +3 -0
  107. data/test/rails/rails_root/script/dbconsole +3 -0
  108. data/test/rails/rails_root/script/destroy +3 -0
  109. data/test/rails/rails_root/script/generate +3 -0
  110. data/test/rails/rails_root/script/performance/benchmarker +3 -0
  111. data/test/rails/rails_root/script/performance/profiler +3 -0
  112. data/test/rails/rails_root/script/performance/request +3 -0
  113. data/test/rails/rails_root/script/plugin +3 -0
  114. data/test/rails/rails_root/script/process/inspector +3 -0
  115. data/test/rails/rails_root/script/process/reaper +3 -0
  116. data/test/rails/rails_root/script/process/spawner +3 -0
  117. data/test/rails/rails_root/script/runner +3 -0
  118. data/test/rails/rails_root/script/server +3 -0
  119. data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +77 -0
  120. data/test/rails/rails_root/spec/controllers/docomo_spec.rb +28 -0
  121. data/test/rails/rails_root/spec/controllers/emobile_spec.rb +35 -0
  122. data/test/rails/rails_root/spec/controllers/filter_spec.rb +157 -0
  123. data/test/rails/rails_root/spec/controllers/pc_spec.rb +11 -0
  124. data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +40 -0
  125. data/test/rails/rails_root/spec/controllers/template_path_spec.rb +85 -0
  126. data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +96 -0
  127. data/test/rails/rails_root/spec/helpers/helpers_spec.rb +13 -0
  128. data/test/rails/rails_root/spec/rcov.opts +2 -0
  129. data/test/rails/rails_root/spec/rspec.rake +165 -0
  130. data/test/rails/rails_root/spec/spec.opts +4 -0
  131. data/test/rails/rails_root/spec/spec_helper.rb +47 -0
  132. data/test/rails/rails_root/test/performance/browsing_test.rb +9 -0
  133. data/test/rails/rails_root/test/test_helper.rb +38 -0
  134. data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +7 -0
  135. data/test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE +7 -0
  136. data/{README → test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc} +15 -17
  137. data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +116 -0
  138. data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +3 -0
  139. data/test/rails/rails_root/vendor/plugins/jpmobile/install.rb +1 -0
  140. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +42 -0
  141. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/datum_conv.rb +72 -0
  142. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +42 -0
  143. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +19 -0
  144. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +123 -0
  145. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/au.rb +1287 -0
  146. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +3908 -0
  147. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/docomo.rb +255 -0
  148. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/softbank.rb +477 -0
  149. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +20 -0
  150. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +173 -0
  151. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +185 -0
  152. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +11 -0
  153. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +142 -0
  154. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +13 -0
  155. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +73 -0
  156. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +97 -0
  157. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +33 -0
  158. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +97 -0
  159. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/emobile.rb +17 -0
  160. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +110 -0
  161. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +39 -0
  162. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_display_info_docomo.rb +688 -0
  163. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +22 -0
  164. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +12 -0
  165. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_emobile.rb +10 -0
  166. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +17 -0
  167. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +117 -0
  168. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +67 -0
  169. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +44 -0
  170. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +105 -0
  171. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +21 -0
  172. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +9 -0
  173. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec.opts +6 -0
  174. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +36 -0
  175. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +31 -0
  176. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_ua_spec.rb +42 -0
  177. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +93 -0
  178. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +5 -0
  179. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +28 -0
  180. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +60 -0
  181. data/test/rails/rails_root/vendor/plugins/jpmobile/tasks/jpmobile_tasks.rake +59 -0
  182. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/emoji/genregexp.rb +47 -0
  183. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_au_emoticon_table.rb +34 -0
  184. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_docomo_emoticon_table.rb +34 -0
  185. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_emoticon_conversion_table.rb +107 -0
  186. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_softbank_emoticon_table.rb +32 -0
  187. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/list_gps_unsupported_au.rb +23 -0
  188. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_display_info_docomo.rb +45 -0
  189. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +29 -0
  190. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_willcom.rb +17 -0
  191. data/tools/update_ip_addresses_au.rb +15 -5
  192. metadata +188 -22
@@ -0,0 +1,36 @@
1
+ unless Spec.const_defined?(:Rails)
2
+ dir = File.dirname(__FILE__)
3
+
4
+ # jpmobileの読み込み
5
+ require 'rubygems'
6
+ require 'action_controller'
7
+ require 'action_mailer'
8
+ require 'initializer'
9
+ require dir+'/../lib/jpmobile'
10
+
11
+ # set (dummy) RAILS_ROOT
12
+ RAILS_ROOT=dir+"/.."
13
+
14
+ # load RSpec on Rails
15
+ rspec_base = dir + '/../vendor/plugins/rspec-rails/lib'
16
+ $LOAD_PATH.unshift rspec_base
17
+ ActiveSupport::Dependencies.load_paths.unshift rspec_base
18
+ ActiveSupport::Dependencies.load_once_paths.unshift rspec_base
19
+
20
+ # application.rb を先に読ませる
21
+ $LOAD_PATH.unshift "#{dir}/../spec_resources/controllers"
22
+ require 'application'
23
+
24
+ # setup resources
25
+ Dir[File.expand_path("#{dir}/../spec_resources/**/*.rb")].sort.each do |file|
26
+ require file
27
+ end
28
+
29
+ # setup routes
30
+ ActionController::Routing::Routes.draw do |map|
31
+ map.connect ':controller/:action/:id.:format'
32
+ map.connect ':controller/:action/:id'
33
+ end
34
+
35
+ require 'spec/rails'
36
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Jpmobile::Email' do
4
+
5
+ Spec::Fixture::Base.new self, :email_addr => :carrier do
6
+
7
+ it '#detect should return :carrier when take :email_addr as EmailAddr' do |email_addr, carrier|
8
+ Jpmobile::Email.detect(email_addr).should == carrier
9
+ end
10
+
11
+ set_fixtures([
12
+ ['example@example.ne.jp' => nil ],
13
+ ['test@docomo.ne.jp' => Jpmobile::Mobile::Docomo ],
14
+ ['test@docomo.ne.jp.jp' => nil ],
15
+ ['a(--)l@ezweb.ne.jp' => Jpmobile::Mobile::Au ],
16
+ ['a(--)l@ezweb.ne.jp.jp' => nil ],
17
+ ['dadaea@pdx.ne.jp' => Jpmobile::Mobile::Willcom ],
18
+ ['dadaea@pdx.ne.jp.jp' => nil ],
19
+ ['xxxe@dj.pdx.ne.jp' => Jpmobile::Mobile::Willcom ],
20
+ ['xxxe@dj.pdx.ne.jp.jp' => nil ],
21
+ ['oeeikx@softbank.ne.jp' => Jpmobile::Mobile::Softbank ],
22
+ ['oeeikx@softbank.ne.jp.jp' => nil ],
23
+ ['eaae@disney.ne.jp' => Jpmobile::Mobile::Softbank ],
24
+ ['eaae@disney.ne.jp.jp' => nil ],
25
+ ['iiiaa@r.vodafone.ne.jp' => Jpmobile::Mobile::Vodafone ],
26
+ ['iiiaa@r.vodafone.ne.jp.jp' => nil ],
27
+ ['aaaaa.aaaa@jp-h.ne.jp' => Jpmobile::Mobile::Jphone ],
28
+ ['aaaaa.aaaa@jp-h.ne.jp.jp' => nil ],
29
+ ])
30
+ end.run
31
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Jpmobile::RequestWithMobile' do
4
+ before(:all) do
5
+ ReqClass = Class.new
6
+ ReqClass.class_eval do
7
+ include Jpmobile::RequestWithMobile
8
+
9
+ def initialize user_agent
10
+ @user_agent = user_agent
11
+ end
12
+
13
+ def user_agent
14
+ @user_agent
15
+ end
16
+ end
17
+ end
18
+
19
+ Spec::Fixture::Base.new self, :carrier => :user_agent do
20
+
21
+ it '#mobile should return :carrier when take :user_agent as UserAgent' do |carrier, user_agent|
22
+ ReqClass.new(user_agent).mobile.class.should == carrier
23
+ end
24
+
25
+ set_fixtures([
26
+ [ Jpmobile::Mobile::Docomo => 'DoCoMo/2.0 SH902i(c100;TB;W24H12)' ],
27
+ [ Jpmobile::Mobile::Docomo => 'DoCoMo/1.0/SO506iC/c20/TB/W20H10' ],
28
+ [ Jpmobile::Mobile::Docomo => 'DoCoMo/2.0 D902i(c100;TB;W23H16;ser999999999999999;icc0000000000000000000f)' ],
29
+ [ Jpmobile::Mobile::Au => 'KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0' ],
30
+ [ Jpmobile::Mobile::Au => 'UP.Browser/3.04-KCTA UP.Link/3.4.5.9' ],
31
+ [ Jpmobile::Mobile::Softbank => 'SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1' ],
32
+ [ Jpmobile::Mobile::Softbank => 'Semulator' ],
33
+ [ 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' ],
34
+ [ Jpmobile::Mobile::Jphone => 'J-PHONE/4.3/V603SH/SNXXXX0000000 SH/0007aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.3.2' ],
35
+ [ Jpmobile::Mobile::Jphone => 'J-EMULATOR' ],
36
+ [ Jpmobile::Mobile::Willcom => 'Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0' ],
37
+ [ Jpmobile::Mobile::Ddipocket => 'Mozilla/3.0(DDIPOCKET;KYOCERA/AH-K3001V/1.8.2.71.000000/0.1/C100) Opera 7.0'],
38
+ [ Jpmobile::Mobile::Emobile => 'emobile/1.0.0 (H11T; like Gecko; Wireless) NetFront/3.4' ],
39
+ [ NilClass => 'Googlebot' ],
40
+ ])
41
+ end.run
42
+ end
@@ -0,0 +1,93 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Jpmobile::Mobile' do
4
+ Spec::Fixture::Base.new self, [ :klass, :carrier ] => :expected do
5
+ filters({
6
+ :klass => proc {|val| Jpmobile::Mobile.const_get(val) },
7
+ :carrier => proc {|val| "#{val}?" },
8
+ })
9
+
10
+ desc_filters({
11
+ :klass => proc {|val| "::#{val.to_s}" },
12
+ :carrier => proc {|val| "#{val}?" },
13
+ })
14
+
15
+ it ":klass#:carrier should be return :expected" do |input, expected|
16
+ input[:klass].new({}).__send__(input[:carrier]).should == expected
17
+ end
18
+
19
+ set_fixtures([
20
+ [ %w[ Docomo docomo ] => true ],
21
+ [ %w[ Docomo au ] => false ],
22
+ [ %w[ Docomo softbank ] => false ],
23
+ [ %w[ Docomo vodafone ] => false ],
24
+ [ %w[ Docomo jphone ] => false ],
25
+ [ %w[ Docomo emobile ] => false ],
26
+ [ %w[ Docomo willcom ] => false ],
27
+ [ %w[ Docomo ddipocket ] => false ],
28
+
29
+ [ %w[ Au docomo ] => false ],
30
+ [ %w[ Au au ] => true ],
31
+ [ %w[ Au softbank ] => false ],
32
+ [ %w[ Au vodafone ] => false ],
33
+ [ %w[ Au jphone ] => false ],
34
+ [ %w[ Au emobile ] => false ],
35
+ [ %w[ Au willcom ] => false ],
36
+ [ %w[ Au ddipocket ] => false ],
37
+
38
+ [ %w[ Softbank docomo ] => false ],
39
+ [ %w[ Softbank au ] => false ],
40
+ [ %w[ Softbank softbank ] => true ],
41
+ [ %w[ Softbank vodafone ] => false ],
42
+ [ %w[ Softbank jphone ] => false ],
43
+ [ %w[ Softbank emobile ] => false ],
44
+ [ %w[ Softbank willcom ] => false ],
45
+ [ %w[ Softbank ddipocket ] => false ],
46
+
47
+ [ %w[ Vodafone docomo ] => false ],
48
+ [ %w[ Vodafone au ] => false ],
49
+ [ %w[ Vodafone softbank ] => true ],
50
+ [ %w[ Vodafone vodafone ] => true ],
51
+ [ %w[ Vodafone jphone ] => false ],
52
+ [ %w[ Vodafone emobile ] => false ],
53
+ [ %w[ Vodafone willcom ] => false ],
54
+ [ %w[ Vodafone ddipocket ] => false ],
55
+
56
+ [ %w[ Jphone docomo ] => false ],
57
+ [ %w[ Jphone au ] => false ],
58
+ [ %w[ Jphone softbank ] => true ],
59
+ [ %w[ Jphone vodafone ] => true ],
60
+ [ %w[ Jphone jphone ] => true ],
61
+ [ %w[ Jphone emobile ] => false ],
62
+ [ %w[ Jphone willcom ] => false ],
63
+ [ %w[ Jphone ddipocket ] => false ],
64
+
65
+ [ %w[ Emobile docomo ] => false ],
66
+ [ %w[ Emobile au ] => false ],
67
+ [ %w[ Emobile softbank ] => false ],
68
+ [ %w[ Emobile vodafone ] => false ],
69
+ [ %w[ Emobile jphone ] => false ],
70
+ [ %w[ Emobile emobile ] => true ],
71
+ [ %w[ Emobile willcom ] => false ],
72
+ [ %w[ Emobile ddipocket ] => false ],
73
+
74
+ [ %w[ Willcom docomo ] => false ],
75
+ [ %w[ Willcom au ] => false ],
76
+ [ %w[ Willcom softbank ] => false ],
77
+ [ %w[ Willcom vodafone ] => false ],
78
+ [ %w[ Willcom jphone ] => false ],
79
+ [ %w[ Willcom emobile ] => false ],
80
+ [ %w[ Willcom willcom ] => true ],
81
+ [ %w[ Willcom ddipocket ] => false ],
82
+
83
+ [ %w[ Ddipocket docomo ] => false ],
84
+ [ %w[ Ddipocket au ] => false ],
85
+ [ %w[ Ddipocket softbank ] => false ],
86
+ [ %w[ Ddipocket vodafone ] => false ],
87
+ [ %w[ Ddipocket jphone ] => false ],
88
+ [ %w[ Ddipocket emobile ] => false ],
89
+ [ %w[ Ddipocket willcom ] => true ],
90
+ [ %w[ Ddipocket ddipocket ] => true ],
91
+ ])
92
+ end.run
93
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'spec/fixture' # gem rspec-fixture
4
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib')))
5
+ require 'jpmobile'
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Jpmobile::Util, ".deep_apply" do
4
+ it 'nilのときはnilを返すこと' do
5
+ Jpmobile::Util.deep_apply(nil) {|obj| obj }.should equal(nil)
6
+ end
7
+
8
+ it 'trueのときはtrueを返すこと' do
9
+ Jpmobile::Util.deep_apply(true) {|obj| obj }.should equal(true)
10
+ end
11
+
12
+ it 'falseのときはそのまま値を返すこと' do
13
+ Jpmobile::Util.deep_apply(false) {|obj| obj }.should equal(false)
14
+ end
15
+
16
+ it 'Tempfileのインスタンスのときはそのまま値を返すこと' do
17
+ temp = Tempfile.new('test')
18
+ Jpmobile::Util.deep_apply(temp) {|obj| obj}.object_id.should equal(temp.object_id)
19
+ # 本来 Jpmobile::Util.deep_apply(temp) {|obj| obj }.should equal(temp) が通るべきのような。
20
+ # 参考 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/41720
21
+ end
22
+
23
+ it 'StringIOのインスタンスのときはそのまま値を返すこと' do
24
+ string_io = StringIO.new('test')
25
+ Jpmobile::Util.deep_apply(string_io) {|obj| obj }.should equal(string_io)
26
+ end
27
+ end
28
+
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Jpmobile::Mobile::valid_ip?' do
4
+ Spec::Fixture::Base.new self, :remote_ip => :carrier do
5
+ it 'should be return true if :remote_ip is in :carrier address' do |remote_ip, carrier|
6
+ Jpmobile::Mobile.const_get(carrier).valid_ip?(remote_ip).should == true
7
+ end
8
+
9
+ set_fixtures([
10
+ [ '210.153.84.1' => :Docomo ],
11
+ [ '210.153.84.254' => :Docomo ],
12
+ [ '210.230.128.225' => :Au ],
13
+ [ '210.230.128.238' => :Au ],
14
+ [ '123.108.236.1' => :Softbank ],
15
+ [ '123.108.236.254' => :Softbank ],
16
+ [ '123.108.236.1' => :Vodafone ],
17
+ [ '123.108.236.254' => :Vodafone ],
18
+ [ '123.108.236.1' => :Jphone ],
19
+ [ '123.108.236.254' => :Jphone ],
20
+ [ '61.198.142.1' => :Willcom ],
21
+ [ '61.198.142.254' => :Willcom ],
22
+ [ '61.198.142.1' => :Ddipocket ],
23
+ [ '61.198.142.254' => :Ddipocket ],
24
+ [ '117.55.1.224' => :Emobile ],
25
+ [ '117.55.1.254' => :Emobile ],
26
+ ])
27
+ end.run
28
+
29
+ Spec::Fixture::Base.new self, :remote_ip => :carrier do
30
+ it 'should not be return true if :remote_ip is in :carrier address' do |remote_ip, carrier|
31
+ Jpmobile::Mobile.const_get(carrier).valid_ip?(remote_ip).should_not == true
32
+ end
33
+
34
+ set_fixtures([
35
+ [ '127.0.0.1' => :Docomo ],
36
+ [ '210.153.83.1' => :Docomo ],
37
+ [ '210.153.83.254' => :Docomo ],
38
+ [ '127.0.0.1' => :Au ],
39
+ [ '210.169.41.1' => :Au ],
40
+ [ '210.169.41.254' => :Au ],
41
+ [ '127.0.0.1' => :Softbank ],
42
+ [ '123.108.238.1' => :Softbank ],
43
+ [ '123.108.238.254' => :Softbank ],
44
+ [ '127.0.0.1' => :Vodafone ],
45
+ [ '123.108.238.1' => :Vodafone ],
46
+ [ '123.108.238.254' => :Vodafone ],
47
+ [ '127.0.0.1' => :Jphone ],
48
+ [ '123.108.238.1' => :Jphone ],
49
+ [ '123.108.238.254' => :Jphone ],
50
+ [ '127.0.0.1' => :Willcom ],
51
+ [ '61.198.144.1' => :Willcom ],
52
+ [ '61.198.144.254' => :Willcom ],
53
+ [ '127.0.0.1' => :Ddipocket ],
54
+ [ '61.198.144.1' => :Ddipocket ],
55
+ [ '61.198.144.254' => :Ddipocket ],
56
+ [ '127.0.0.1' => :Emobile ],
57
+ [ '117.55.1.223' => :Emobile ],
58
+ ])
59
+ end.run
60
+ end
@@ -0,0 +1,59 @@
1
+ # desc "Explaining what the task does"
2
+ # task :jpmobile do
3
+ # # Task goes here
4
+ # end
5
+
6
+ begin
7
+ require 'spec'
8
+ require 'spec/rake/spectask'
9
+ namespace :spec do
10
+ desc 'run unit testing (core test)'
11
+ Spec::Rake::SpecTask.new(:unit) do |t|
12
+ spec_dir = File.join(File.dirname(__FILE__), '..', 'spec')
13
+ t.spec_opts = File.read(File.join(spec_dir, 'spec.opts')).split
14
+ t.spec_files = FileList[File.join(spec_dir, 'unit', '**', '*_spec.rb')]
15
+ end
16
+ end
17
+ rescue LoadError
18
+ warn "RSpec is not installed. Some tasks were skipped. please install rspec"
19
+ end
20
+
21
+ namespace :test do
22
+ desc "run jpmobile legacy tests"
23
+ Rake::TestTask.new(:legacy) do |t|
24
+ t.libs << 'lib'
25
+ t.pattern = 'test/legacy/**/*_test.rb'
26
+ t.verbose = true
27
+ end
28
+ desc "Generate rails app and run jpmobile tests in the app"
29
+ task :rails, [:versions] do |t, args|
30
+ rails_versions = args.versions.split(",") rescue ["2.2.2"]
31
+ rails_versions.each do |rails_version|
32
+ puts "Running tests in Rails #{rails_version}"
33
+
34
+ # generate rails app
35
+ rails_root = "test/rails/rails_root"
36
+ FileUtils.rm_rf(rails_root)
37
+ FileUtils.mkdir_p(rails_root)
38
+ system "rails _#{rails_version}_ -q --force #{rails_root}"
39
+
40
+ # setup jpmobile
41
+ plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile')
42
+ FileUtils.mkdir_p(plugin_path)
43
+ FileList["*"].exclude("test").each do |file|
44
+ FileUtils.cp_r(file, plugin_path)
45
+ end
46
+
47
+ # setup tests
48
+ FileList["test/rails/overrides/*"].each do |file|
49
+ FileUtils.cp_r(file, rails_root)
50
+ end
51
+
52
+ # run tests in rails
53
+ cd rails_root
54
+ sh "rake db:migrate"
55
+ sh "rake spec"
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,47 @@
1
+ require 'scanf'
2
+
3
+ def to_ranges(array)
4
+ sorted = array.sort.uniq
5
+ results = []
6
+ start = nil
7
+ for i in 0...sorted.size
8
+ start ||= sorted[i]
9
+ if i == sorted.size-1 || sorted[i+1] - sorted[i] > 1
10
+ if start == sorted[i]
11
+ results << start
12
+ else
13
+ results << (start..sorted[i])
14
+ end
15
+ start = nil
16
+ end
17
+ end
18
+ results
19
+ end
20
+
21
+ def ranges_to_regexp(array)
22
+ r = ""
23
+ array.each do |x|
24
+ if x.is_a? Range
25
+ r << "\\x%02x-\\x%02x" % [x.first, x.last]
26
+ else
27
+ r << "\\x%02x" % x
28
+ end
29
+ end
30
+ r
31
+ end
32
+
33
+ h = Hash.new {|h,k| h[k]=[]}
34
+
35
+ ARGF.each do |l|
36
+ l.chomp!
37
+ sjis_bin = [[l].pack("H4")].first
38
+ a = l.scanf("%02X%02X")
39
+ h[a.first] << a.last
40
+ end
41
+
42
+ re = []
43
+ h.sort.each do |k,v|
44
+ re << "\\x%02x"%k + '['+ranges_to_regexp(to_ranges(v))+']'
45
+ p ["\\x%02x"%k, to_ranges(v), ranges_to_regexp(to_ranges(v))]
46
+ end
47
+ puts re.join('|')
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # http://www.au.kddi.com/ezfactory/tec/spec/pdf/typeD.pdf から生成
4
+ # - OSXのpreviewで開き、すべてを選択してコピーし、テキストファイルに落とす
5
+ # - http://moriq.tdiary.net/20070212.html#p01
6
+ # などの手段によって生成する。
7
+
8
+ table = []
9
+ open("au.txt") do |f|
10
+ f.each do |l|
11
+ l.chomp!
12
+ l.scan( /(([0-9A-F] )+)/ ) do |s|
13
+ s = s[0].gsub!(/ /, "")
14
+ next if s.size < 16
15
+ out = s[s.size-16,16]
16
+ table << a = [0,4,8,12].map{|i| out[i,4]}
17
+ end
18
+ end
19
+ end
20
+
21
+ open(File.dirname(__FILE__)+"/../lib/jpmobile/emoticon/au.rb","w") do |f|
22
+ f.puts "Jpmobile::Emoticon::AU_SJIS_TO_UNICODE = {"
23
+ table.each do |a|
24
+ f.puts " 0x%s=>0x%s," % [a[0],a[1]]
25
+ end
26
+ f.puts "}.freeze"
27
+ f.puts "Jpmobile::Emoticon::AU_UNICODE_TO_SJIS = Jpmobile::Emoticon::AU_SJIS_TO_UNICODE.invert.freeze"
28
+ # EmailJIS -> UNICODE
29
+ f.puts "Jpmobile::Emoticon::AU_EMAILJIS_TO_UNICODE = {"
30
+ table.each do |a|
31
+ f.puts " 0x%s=>0x%s," % [a[2],a[1]]
32
+ end
33
+ f.puts "}.freeze"
34
+ end