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,8 +1,7 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # = 文字コードフィルタ
2
3
  # thanks to masuidrive <masuidrive (at) masuidrive.jp>
3
4
 
4
- require 'scanf'
5
-
6
5
  class ActionController::Base #:nodoc:
7
6
  def self.mobile_filter(options={})
8
7
  options = {:emoticon=>true, :hankaku=>false}.update(options)
@@ -99,7 +98,7 @@ module Jpmobile
99
98
  end
100
99
  private
101
100
  def filter(str, from, to)
102
- str = str.clone
101
+ str = str.dup
103
102
  from.each_with_index do |int, i|
104
103
  str.gsub!(int, to[i])
105
104
  end
@@ -50,6 +50,12 @@ module Jpmobile::Mobile
50
50
  return false
51
51
  end
52
52
 
53
+ # リクエストがこのクラスに属するか調べる
54
+ # メソッド名に関して非常に不安
55
+ def self.check_request(request)
56
+ self::USER_AGENT_REGEXP && request.user_agent =~ self::USER_AGENT_REGEXP
57
+ end
58
+
53
59
  #XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
54
60
  Jpmobile::Mobile.carriers.each do |carrier|
55
61
  carrier_class = Jpmobile::Mobile.const_get(carrier)
@@ -76,8 +76,31 @@ module Jpmobile::Mobile
76
76
 
77
77
  # cookieに対応しているか?
78
78
  def supports_cookie?
79
- false
79
+ imode_browser_version != '1.0'
80
80
  end
81
+
82
+ # i-mode ブラウザのバージョンを返す。
83
+ # http://labs.unoh.net/2009/07/i_20.html
84
+ def imode_browser_version
85
+ ver = '1.0'
86
+ case @request.env['HTTP_USER_AGENT']
87
+ when %r{^DoCoMo/1.0/}
88
+ # 必ずv1.0
89
+ when %r{^DoCoMo/2.0 }
90
+ @request.env['HTTP_USER_AGENT'] =~ / (\w+)\(c(\d+);/
91
+ model = $1
92
+ cache_size = $2.to_i
93
+
94
+ ver = cache_size >= 500 ? (%w(P03B P05B L01B).member?(model) ? '2.0LE' : '2.0') : '1.0'
95
+ else
96
+ # DoCoMo/3.0以降等は、とりあえず非v1.0扱い
97
+ ver = '2.0'
98
+ end
99
+
100
+ ver
101
+ end
102
+
103
+
81
104
  private
82
105
  # モデル名を返す。
83
106
  def model_name
@@ -1,4 +1,4 @@
1
- Jpmobile::Mobile::Au::IP_ADDRESSES =
1
+ Jpmobile::Mobile::Au::IP_ADDRESSES =
2
2
  ["210.230.128.224/28",
3
3
  "121.111.227.160/27",
4
4
  "61.117.1.0/28",
@@ -23,4 +23,5 @@ Jpmobile::Mobile::Au::IP_ADDRESSES =
23
23
  "111.86.142.0/26",
24
24
  "111.86.141.64/26",
25
25
  "111.86.141.128/26",
26
- "111.86.141.192/26"].map {|ip| IPAddr.new(ip) }
26
+ "111.86.141.192/26",
27
+ "118.159.133.192/26"].map {|ip| IPAddr.new(ip) }
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # = IPアドレス帯域テーブル(手動更新分)
2
3
  # == DoCoMo
3
4
  # http://www.nttdocomo.co.jp/service/imode/make/content/ip/index.html
@@ -8,5 +9,7 @@ Jpmobile::Mobile::Docomo::IP_ADDRESSES = %w(
8
9
  210.153.86.0/24
9
10
  124.146.174.0/24
10
11
  124.146.175.0/24
12
+ 202.229.176.0/24
13
+ 202.229.177.0/24
14
+ 202.229.178.0/24
11
15
  ).map {|ip| IPAddr.new(ip) }
12
-
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
1
3
  # jpmobile の各機能を提供するモジュール
2
4
  # envメソッドと、parameter あるいは params メソッドが実装されている必要がある。
3
5
  # 今のところはRack::RequestとActionController::AbstractRequestに対応しているはず。
@@ -31,11 +33,12 @@ module Jpmobile
31
33
  # 携帯電話の機種に応じて Mobile::xxx を返す。
32
34
  # 携帯電話でない場合はnilを返す。
33
35
  def mobile
36
+ @__mobile ||= nil
34
37
  return @__mobile if @__mobile
35
38
 
36
39
  Jpmobile::Mobile.carriers.each do |const|
37
40
  c = Jpmobile::Mobile.const_get(const)
38
- return @__mobile = c.new(self) if c::USER_AGENT_REGEXP && user_agent =~ c::USER_AGENT_REGEXP
41
+ return @__mobile = c.new(self) if c.check_request(self)
39
42
  end
40
43
  nil
41
44
  end
@@ -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
@@ -1,25 +1,23 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe 'Jpmobile::RequestWithMobile' do
4
- before(:all) do
5
- ReqClass = Class.new
6
- ReqClass.class_eval do
7
- include Jpmobile::RequestWithMobile
4
+ Spec::Fixture::Base.new self, :carrier => :user_agent do
5
+ def request_class
6
+ Class.new do
7
+ include Jpmobile::RequestWithMobile
8
8
 
9
- def initialize user_agent
10
- @user_agent = user_agent
11
- end
9
+ def initialize user_agent
10
+ @user_agent = user_agent
11
+ end
12
12
 
13
- def user_agent
14
- @user_agent
13
+ def user_agent
14
+ @user_agent
15
+ end
15
16
  end
16
17
  end
17
- end
18
-
19
- Spec::Fixture::Base.new self, :carrier => :user_agent do
20
18
 
21
19
  it '#mobile should return :carrier when take :user_agent as UserAgent' do |carrier, user_agent|
22
- ReqClass.new(user_agent).mobile.class.should == carrier
20
+ request_class.new(user_agent).mobile.class.should == carrier
23
21
  end
24
22
 
25
23
  set_fixtures([
@@ -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,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper')
4
+
5
+ describe Jpmobile::Util, ".deep_apply" do
6
+ it 'nilのときはnilを返すこと' do
7
+ Jpmobile::Util.deep_apply(nil) {|obj| obj }.should equal(nil)
8
+ end
9
+
10
+ it 'trueのときはtrueを返すこと' do
11
+ Jpmobile::Util.deep_apply(true) {|obj| obj }.should equal(true)
12
+ end
13
+
14
+ it 'falseのときはそのまま値を返すこと' do
15
+ Jpmobile::Util.deep_apply(false) {|obj| obj }.should equal(false)
16
+ end
17
+
18
+ it 'Tempfileのインスタンスのときはそのまま値を返すこと' do
19
+ temp = Tempfile.new('test')
20
+ Jpmobile::Util.deep_apply(temp) {|obj| obj}.object_id.should equal(temp.object_id)
21
+ # 本来 Jpmobile::Util.deep_apply(temp) {|obj| obj }.should equal(temp) が通るべきのような。
22
+ # 参考 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/41720
23
+ end
24
+
25
+ it 'StringIOのインスタンスのときはそのまま値を返すこと' do
26
+ string_io = StringIO.new('test')
27
+ Jpmobile::Util.deep_apply(string_io) {|obj| obj }.should equal(string_io)
28
+ end
29
+ end
30
+
@@ -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
@@ -29,7 +29,7 @@ namespace :test do
29
29
  task :rails, [:versions] do |t, args|
30
30
  rails_root = "test/rails/rails_root"
31
31
  relative_root = "../../../"
32
- rails_versions = args.versions.split("/") rescue ["2.3.5"]
32
+ rails_versions = args.versions.split("/") rescue ["2.3.8"]
33
33
 
34
34
  puts "Running tests in Rails #{rails_versions.join(', ')}"
35
35
 
@@ -70,8 +70,8 @@ END
70
70
 
71
71
  # run tests in rails
72
72
  cd rails_root
73
- sh "rake db:migrate"
74
- sh "rake spec"
73
+ ruby "-S rake db:migrate"
74
+ ruby "-S rake spec"
75
75
 
76
76
  cd relative_root
77
77
  end
@@ -1,4 +1,5 @@
1
- require 'test/unit'
1
+ require File.dirname(__FILE__)+'/helper'
2
+
2
3
  module Jpmobile
3
4
  module Mobile
4
5
  require 'jpmobile/mobile/abstract_mobile'