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
@@ -6,64 +6,77 @@ module ParamsOverCookie
6
6
  def self.included(base)
7
7
  base.class_eval do
8
8
  # cookie よりも params を先に見るパッチ
9
- def load_session_with_jpmobile(env)
10
- request = Rack::Request.new(env)
11
- unless @cookie_only
9
+ def extract_session_id_with_jpmobile(env)
10
+ request = ActionDispatch::Request.new(env.dup)
11
+ if request.params[@key] and !@cookie_only
12
12
  sid = request.params[@key]
13
13
  end
14
14
  sid ||= request.cookies[@key]
15
-
16
- sid, session = get_session(env, sid)
17
- [sid, session]
15
+ sid
18
16
  end
19
- alias_method_chain :load_session, :jpmobile
17
+ alias_method_chain :extract_session_id, :jpmobile
20
18
  end
21
19
  end
22
20
  end
23
21
 
24
- module ActionController
25
- # cookie よりも params を先に見るパッチ
26
- Session::AbstractStore.send :include, ParamsOverCookie
27
-
28
- class Base #:nodoc:
29
- class_inheritable_accessor :trans_sid_mode
30
- alias :redirect_to_full_url_without_jpmobile :redirect_to_full_url
31
-
32
- def transit_sid_mode(*args)
33
- STDERR.puts "Method transit_sid is now deprecated. Use trans_sid instead."
34
- trans_sid_mode(*args)
22
+ module ActionDispatch
23
+ module Session
24
+ class AbstractStore
25
+ include ParamsOverCookie
35
26
  end
27
+ end
28
+ end
36
29
 
37
- def redirect_to_full_url(url, status)
38
- if apply_trans_sid? and !url.match(/#{session_key}/)
39
- uri = URI.parse(url)
40
- if uri.query
41
- uri.query += "&#{session_key}=#{jpmobile_session_id}"
30
+ module ActionController
31
+ module Redirecting
32
+ def redirect_to_with_jpmobile(options = {}, response_status = {})
33
+ if apply_trans_sid? and jpmobile_session_id
34
+ case options
35
+ when %r{^\w[\w+.-]*:.*}
36
+ # nothing to do
37
+ when String
38
+ unless options.match(/#{session_key}/)
39
+ url = URI.parse(options)
40
+ if url.query
41
+ url.query += "&#{session_key}=#{jpmobile_session_id}"
42
+ else
43
+ url.query = "#{session_key}=#{jpmobile_session_id}"
44
+ end
45
+ options = url.to_s
46
+ end
47
+ when :back
48
+ # nothing to do
49
+ when Hash
50
+ unless options[session_key.to_sym]
51
+ options[session_key.to_sym] = jpmobile_session_id
52
+ end
42
53
  else
43
- uri.query = "#{session_key}=#{jpmobile_session_id}"
54
+ # nothing to do
44
55
  end
45
- url = uri.to_s
46
56
  end
47
57
 
48
- redirect_to_full_url_without_jpmobile(url, status)
58
+ redirect_to_without_jpmobile(options, response_status)
49
59
  end
50
60
 
61
+ alias_method_chain :redirect_to, :jpmobile
62
+ end
63
+
64
+ class Base #:nodoc:
65
+ class_inheritable_accessor :trans_sid_mode
66
+
51
67
  class << self
52
- # 2.3.x or higher
53
68
  def trans_sid(mode = :mobile)
54
69
  include Jpmobile::TransSid
55
70
  self.trans_sid_mode = mode
56
71
  end
57
-
58
- def transit_sid(*args)
59
- STDERR.puts "Method transit_sid is now deprecated. Use trans_sid instead."
60
- trans_sid(*args)
61
- end
62
72
  end
63
73
 
64
74
  private
65
75
  # trans_sidを適用すべきかを返す。
66
76
  def apply_trans_sid?
77
+ # session_id が blank の場合は適用しない
78
+ return false if trans_sid_mode and jpmobile_session_id.blank?
79
+
67
80
  case trans_sid_mode
68
81
  when :always
69
82
  session.inspect
@@ -87,17 +100,20 @@ module Jpmobile::TransSid #:nodoc:
87
100
 
88
101
  protected
89
102
  # URLにsession_idを追加する。
90
- def default_url_options(options=nil)
103
+ def default_url_options
91
104
  result = super || {}
92
105
  return result unless request # for test process
93
106
  return result unless apply_trans_sid?
94
- return result.merge({ session_key => jpmobile_session_id })
107
+ return result.merge({session_key => jpmobile_session_id})
95
108
  end
96
109
 
97
110
  private
98
111
  # session_keyを返す。
99
112
  def session_key
100
- ActionController::Base.session_options.merge(request.session_options || {})[:key]
113
+ unless key = Rails.application.config.session_options.merge(request.session_options || {})[:key]
114
+ key = ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS[:key]
115
+ end
116
+ key
101
117
  end
102
118
  # session_idを返す
103
119
  def jpmobile_session_id
@@ -111,6 +127,7 @@ module Jpmobile::TransSid #:nodoc:
111
127
  def append_session_id_parameter
112
128
  return unless request # for test process
113
129
  return unless apply_trans_sid?
130
+ return unless jpmobile_session_id
114
131
  response.body.gsub!(%r{(</form>)}i, sid_hidden_field_tag+'\1')
115
132
  end
116
133
  end
@@ -17,5 +17,73 @@ module Jpmobile
17
17
  proc.call(obj)
18
18
  end
19
19
  end
20
+
21
+ def deep_convert(obj, &proc)
22
+ case obj
23
+ when Hash
24
+ new_obj = {}
25
+ obj.each_pair do |key, value|
26
+ new_obj[deep_convert(key.dup, &proc)] = deep_convert(value, &proc)
27
+ end
28
+ new_obj
29
+ when Array
30
+ new_obj = obj.map do |value|
31
+ deep_convert(value, &proc)
32
+ end
33
+ when Symbol
34
+ new_obj = proc.call(obj.to_s).to_sym
35
+ when NilClass, TrueClass, FalseClass, Tempfile, StringIO
36
+ new_obj = obj
37
+ else
38
+ obj = obj.to_param if obj.respond_to?(:to_param)
39
+ new_obj = proc.call(obj)
40
+ end
41
+
42
+ new_obj
43
+ end
44
+
45
+ def sjis(ascii_8bit)
46
+ if ascii_8bit.respond_to?(:force_encoding)
47
+ ascii_8bit.force_encoding("Shift_JIS")
48
+ end
49
+ ascii_8bit
50
+ end
51
+
52
+ def utf8(ascii_8bit)
53
+ if ascii_8bit.respond_to?(:force_encoding)
54
+ ascii_8bit.force_encoding("utf-8")
55
+ end
56
+ ascii_8bit
57
+ end
58
+
59
+ def ascii_8bit(str)
60
+ if str.respond_to?(:force_encoding)
61
+ str.force_encoding("ASCII-8BIT")
62
+ end
63
+ str
64
+ end
65
+
66
+ def utf8_to_sjis(utf8_str)
67
+ if utf8_str.respond_to?(:encode)
68
+ utf8_str.encode("Shift_JIS", :crlf_newline => true)
69
+ else
70
+ NKF.nkf("-m0 -x -Ws", utf8_str).gsub(/\n/, "\r\n")
71
+ end
72
+ end
73
+
74
+ def sjis_to_utf8(sjis_str)
75
+ if sjis_str.respond_to?(:encode)
76
+ sjis_str.encode("UTF-8", :universal_newline => true)
77
+ else
78
+ NKF.nkf("-m0 -x -Sw", sjis_str).gsub(/\r\n/, "\n")
79
+ end
80
+ end
81
+
82
+ def hash_to_utf8(hash)
83
+ new_hash = {}
84
+ hash.each do |keu, value|
85
+ new_hash[utf8(key)] = utf8(value)
86
+ end
87
+ end
20
88
  end
21
89
  end
@@ -1,4 +1,5 @@
1
- unless Spec.const_defined?(:Rails)
1
+ # -*- coding: utf-8 -*-
2
+ unless RSpec.const_defined?(:Rails)
2
3
  dir = File.dirname(__FILE__)
3
4
 
4
5
  # jpmobileの読み込み
@@ -32,5 +33,5 @@ unless Spec.const_defined?(:Rails)
32
33
  map.connect ':controller/:action/:id'
33
34
  end
34
35
 
35
- require 'spec/rails'
36
+ require 'rspec/rails'
36
37
  end
@@ -1,31 +1,25 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
2
 
3
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
4
+ [
5
+ ['example@example.ne.jp' , nil ],
6
+ ['test@docomo.ne.jp' , Jpmobile::Mobile::Docomo ],
7
+ ['test@docomo.ne.jp.jp' , nil ],
8
+ ['a(--)l@ezweb.ne.jp' , Jpmobile::Mobile::Au ],
9
+ ['a(--)l@ezweb.ne.jp.jp' , nil ],
10
+ ['dadaea@pdx.ne.jp' , Jpmobile::Mobile::Willcom ],
11
+ ['dadaea@pdx.ne.jp.jp' , nil ],
12
+ ['xxxe@dj.pdx.ne.jp' , Jpmobile::Mobile::Willcom ],
13
+ ['xxxe@dj.pdx.ne.jp.jp' , nil ],
14
+ ['oeeikx@softbank.ne.jp' , Jpmobile::Mobile::Softbank ],
15
+ ['oeeikx@softbank.ne.jp.jp' , nil ],
16
+ ['eaae@disney.ne.jp' , Jpmobile::Mobile::Softbank ],
17
+ ['eaae@disney.ne.jp.jp' , nil ],
18
+ ['iiiaa@r.vodafone.ne.jp' , Jpmobile::Mobile::Vodafone ],
19
+ ['iiiaa@r.vodafone.ne.jp.jp' , nil ],
20
+ ].each do |email_addr, carrier|
21
+ it "#detect should return #{carrier} when take #{email_addr} as EmailAddr" do
22
+ Jpmobile::Email.detect(email_addr).should == carrier
9
23
  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
24
+ end
31
25
  end
@@ -1,93 +1,65 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
2
 
3
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
- })
4
+ [
5
+ [ %w[ Docomo docomo ] , true ],
6
+ [ %w[ Docomo au ] , false ],
7
+ [ %w[ Docomo softbank ] , false ],
8
+ [ %w[ Docomo vodafone ] , false ],
9
+ [ %w[ Docomo emobile ] , false ],
10
+ [ %w[ Docomo willcom ] , false ],
11
+ [ %w[ Docomo ddipocket ] , false ],
9
12
 
10
- desc_filters({
11
- :klass => proc {|val| "::#{val.to_s}" },
12
- :carrier => proc {|val| "#{val}?" },
13
- })
13
+ [ %w[ Au docomo ] , false ],
14
+ [ %w[ Au au ] , true ],
15
+ [ %w[ Au softbank ] , false ],
16
+ [ %w[ Au vodafone ] , false ],
17
+ [ %w[ Au emobile ] , false ],
18
+ [ %w[ Au willcom ] , false ],
19
+ [ %w[ Au ddipocket ] , false ],
14
20
 
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 ],
21
+ [ %w[ Softbank docomo ] , false ],
22
+ [ %w[ Softbank au ] , false ],
23
+ [ %w[ Softbank softbank ] , true ],
24
+ [ %w[ Softbank vodafone ] , false ],
25
+ [ %w[ Softbank emobile ] , false ],
26
+ [ %w[ Softbank willcom ] , false ],
27
+ [ %w[ Softbank ddipocket ] , false ],
37
28
 
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 ],
29
+ [ %w[ Vodafone docomo ] , false ],
30
+ [ %w[ Vodafone au ] , false ],
31
+ [ %w[ Vodafone softbank ] , true ],
32
+ [ %w[ Vodafone vodafone ] , true ],
33
+ [ %w[ Vodafone emobile ] , false ],
34
+ [ %w[ Vodafone willcom ] , false ],
35
+ [ %w[ Vodafone ddipocket ] , false ],
46
36
 
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 ],
37
+ [ %w[ Emobile docomo ] , false ],
38
+ [ %w[ Emobile au ] , false ],
39
+ [ %w[ Emobile softbank ] , false ],
40
+ [ %w[ Emobile vodafone ] , false ],
41
+ [ %w[ Emobile emobile ] , true ],
42
+ [ %w[ Emobile willcom ] , false ],
43
+ [ %w[ Emobile ddipocket ] , false ],
55
44
 
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 ],
45
+ [ %w[ Willcom docomo ] , false ],
46
+ [ %w[ Willcom au ] , false ],
47
+ [ %w[ Willcom softbank ] , false ],
48
+ [ %w[ Willcom vodafone ] , false ],
49
+ [ %w[ Willcom emobile ] , false ],
50
+ [ %w[ Willcom willcom ] , true ],
51
+ [ %w[ Willcom ddipocket ] , false ],
64
52
 
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
53
+ [ %w[ Ddipocket docomo ] , false ],
54
+ [ %w[ Ddipocket au ] , false ],
55
+ [ %w[ Ddipocket softbank ] , false ],
56
+ [ %w[ Ddipocket vodafone ] , false ],
57
+ [ %w[ Ddipocket emobile ] , false ],
58
+ [ %w[ Ddipocket willcom ] , true ],
59
+ [ %w[ Ddipocket ddipocket ] , true ],
60
+ ].each do |carrier, expected|
61
+ it "#{carrier.first}##{carrier.last}? should be return #{expected}" do
62
+ Jpmobile::Mobile.const_get(carrier.first).new({}, {}).__send__("#{carrier.last}?").should == expected
63
+ end
64
+ end
93
65
  end
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- require 'spec'
3
- require 'spec/fixture' # gem rspec-fixture
2
+ require 'rspec'
4
3
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib')))
5
4
  require 'jpmobile'
@@ -1,4 +1,7 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ # -*- coding: utf-8 -*-
2
+ require 'stringio'
3
+ require 'nkf'
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
5
 
3
6
  describe Jpmobile::Util, ".deep_apply" do
4
7
  it 'nilのときはnilを返すこと' do
@@ -24,5 +27,8 @@ describe Jpmobile::Util, ".deep_apply" do
24
27
  string_io = StringIO.new('test')
25
28
  Jpmobile::Util.deep_apply(string_io) {|obj| obj }.should equal(string_io)
26
29
  end
27
- end
28
30
 
31
+ it "utf8_to_sjis で改行コードが CRLF に変更されること" do
32
+ Jpmobile::Util.utf8_to_sjis("UTF8\nTEXT\n").should == Jpmobile::Util.sjis("UTF8\r\nTEXT\r\n")
33
+ end
34
+ end