jpmobile 0.0.8 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +0 -3
  2. data/{spec/spec.opts → .rspec} +1 -2
  3. data/README.rdoc +122 -128
  4. data/Rakefile +23 -101
  5. data/VERSION.yml +4 -3
  6. data/jpmobile.gemspec +130 -182
  7. data/lib/jpmobile.rb +37 -24
  8. data/lib/jpmobile/docomo_guid.rb +2 -1
  9. data/lib/jpmobile/email.rb +3 -4
  10. data/lib/jpmobile/emoticon.rb +2 -6
  11. data/lib/jpmobile/encoding.rb +29 -0
  12. data/lib/jpmobile/filter.rb +42 -134
  13. data/lib/jpmobile/helpers.rb +5 -18
  14. data/lib/jpmobile/hook_action_controller.rb +24 -16
  15. data/lib/jpmobile/hook_action_view.rb +28 -89
  16. data/lib/jpmobile/mobile/abstract_mobile.rb +21 -4
  17. data/lib/jpmobile/mobile/android.rb +10 -0
  18. data/lib/jpmobile/mobile/au.rb +28 -3
  19. data/lib/jpmobile/mobile/ddipocket.rb +12 -0
  20. data/lib/jpmobile/mobile/display.rb +29 -26
  21. data/lib/jpmobile/mobile/docomo.rb +38 -12
  22. data/lib/jpmobile/mobile/iphone.rb +26 -0
  23. data/lib/jpmobile/mobile/smart_phone.rb +21 -0
  24. data/lib/jpmobile/mobile/softbank.rb +16 -41
  25. data/lib/jpmobile/mobile/vodafone.rb +17 -0
  26. data/lib/jpmobile/mobile/willcom.rb +1 -10
  27. data/lib/jpmobile/mobile/windows_phone.rb +10 -0
  28. data/lib/jpmobile/position.rb +4 -3
  29. data/lib/jpmobile/rack.rb +43 -0
  30. data/lib/jpmobile/rack/filter.rb +51 -0
  31. data/lib/jpmobile/rack/mobile_carrier.rb +33 -0
  32. data/lib/jpmobile/rack/params_filter.rb +47 -0
  33. data/lib/jpmobile/rails.rb +22 -0
  34. data/lib/jpmobile/request_with_mobile.rb +8 -12
  35. data/lib/jpmobile/trans_sid.rb +44 -26
  36. data/lib/jpmobile/util.rb +68 -0
  37. data/{tasks → lib/tasks}/jpmobile_tasks.rake +32 -13
  38. data/spec/rack/jpmobile/android_spec.rb +20 -0
  39. data/spec/rack/jpmobile/au_spec.rb +206 -0
  40. data/spec/rack/jpmobile/docomo_spec.rb +237 -0
  41. data/spec/rack/jpmobile/emoticon_spec.rb +215 -0
  42. data/spec/rack/jpmobile/filter_spec.rb +181 -0
  43. data/spec/rack/jpmobile/iphone_spec.rb +32 -0
  44. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +39 -0
  45. data/spec/rack/jpmobile/params_filter_spec.rb +193 -0
  46. data/spec/rack/jpmobile/softbank_spec.rb +123 -0
  47. data/spec/rack/jpmobile/willcom_spec.rb +67 -0
  48. data/spec/rack/jpmobile/windows_phone.rb +20 -0
  49. data/spec/rack_helper.rb +86 -0
  50. data/spec/spec_helper.rb +3 -2
  51. data/spec/unit/detect_by_email_spec.rb +21 -27
  52. data/spec/unit/is_carrier_spec.rb +56 -84
  53. data/spec/unit/spec_helper.rb +1 -2
  54. data/spec/unit/util_spec.rb +2 -2
  55. data/spec/unit/valid_ip_spec.rb +43 -52
  56. data/test/legacy/autoload_test.rb +1 -3
  57. data/test/legacy/emoticon_test.rb +5 -6
  58. data/test/legacy/helper.rb +0 -71
  59. data/test/rails/overrides/.rspec +5 -0
  60. data/test/rails/overrides/Gemfile +32 -0
  61. data/test/rails/overrides/app/controllers/docomo_guid_always_controller.rb +3 -0
  62. data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +5 -0
  63. data/test/rails/overrides/app/controllers/docomo_guid_docomo_controller.rb +3 -0
  64. data/test/rails/overrides/app/controllers/filter_controller.rb +0 -34
  65. data/test/rails/overrides/app/controllers/filter_controller_base.rb +19 -0
  66. data/test/rails/overrides/app/controllers/hankaku_filter_controller.rb +3 -0
  67. data/test/rails/overrides/app/controllers/links_controller.rb +28 -0
  68. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  69. data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
  70. data/test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb +4 -0
  71. data/test/rails/overrides/app/controllers/trans_sid_always_controller.rb +3 -0
  72. data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -0
  73. data/test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb +3 -0
  74. data/test/rails/overrides/app/controllers/trans_sid_none_controller.rb +3 -0
  75. data/test/rails/overrides/app/views/links/au_gps.html.erb +1 -0
  76. data/test/rails/overrides/app/views/links/au_location.html.erb +1 -0
  77. data/test/rails/overrides/app/views/links/docomo_foma_gps.html.erb +1 -0
  78. data/test/rails/overrides/app/views/links/docomo_openiarea.html.erb +1 -0
  79. data/test/rails/overrides/app/views/links/docomo_utn.html.erb +1 -0
  80. data/test/rails/overrides/app/views/links/link.html.erb +1 -0
  81. data/test/rails/overrides/app/views/links/show_all.html.erb +1 -0
  82. data/test/rails/overrides/app/views/links/softbank_location.html.erb +1 -0
  83. data/test/rails/overrides/app/views/links/willcom_location.html.erb +1 -0
  84. data/test/rails/overrides/app/views/template_path/_partial_smart_phone.html.erb +1 -0
  85. data/test/rails/overrides/app/views/template_path/_partial_smart_phone_iphone.html.erb +1 -0
  86. data/test/rails/overrides/app/views/template_path/index_smart_phone.html.erb +1 -0
  87. data/test/rails/overrides/app/views/template_path/index_smart_phone_iphone.html.erb +1 -0
  88. data/test/rails/overrides/app/views/template_path/show_mobile.html.erb +1 -0
  89. data/test/rails/overrides/app/views/template_path/show_mobile_docomo.html.erb +1 -0
  90. data/test/rails/overrides/autotest/discover.rb +2 -0
  91. data/test/rails/overrides/config/initializers/jpmobile_generator.rb +1 -0
  92. data/test/rails/overrides/config/routes.rb +58 -0
  93. data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +16 -0
  94. data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -2
  95. data/test/rails/overrides/spec/{controllers → requests}/docomo_guid_spec.rb +37 -14
  96. data/test/rails/overrides/spec/{controllers → requests}/docomo_spec.rb +11 -8
  97. data/test/rails/overrides/spec/{controllers → requests}/emobile_spec.rb +24 -8
  98. data/test/rails/overrides/spec/requests/filter_spec.rb +171 -0
  99. data/test/rails/overrides/spec/requests/helpers_spec.rb +187 -0
  100. data/test/rails/overrides/spec/requests/pc_spec.rb +22 -0
  101. data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +21 -0
  102. data/test/rails/overrides/spec/requests/template_path_spec.rb +234 -0
  103. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +142 -0
  104. data/test/rails/overrides/spec/spec_helper.rb +17 -48
  105. data/test/sinatra/guestbook.rb +40 -0
  106. data/test/sinatra/test/filter_test.rb +39 -0
  107. metadata +185 -312
  108. data/lib/jpmobile/hook_request.rb +0 -5
  109. data/lib/jpmobile/rack/auth.rb +0 -55
  110. data/lib/jpmobile/rack/combined_logger.rb +0 -54
  111. data/lib/jpmobile/rack/request.rb +0 -7
  112. data/lib/jpmobile/rack/trans_sid.rb +0 -14
  113. data/lib/jpmobile/version.rb +0 -9
  114. data/spec/unit/detect_by_ua_spec.rb +0 -40
  115. data/test/legacy/au_test.rb +0 -173
  116. data/test/legacy/docomo_test.rb +0 -187
  117. data/test/legacy/emoticon_functional_test.rb +0 -195
  118. data/test/legacy/filter_test.rb +0 -34
  119. data/test/legacy/helpers_test.rb +0 -217
  120. data/test/legacy/softbank_test.rb +0 -183
  121. data/test/legacy/willcom_test.rb +0 -56
  122. data/test/rails/2.3.2/spec/controllers/trans_sid_spec.rb +0 -99
  123. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +0 -13
  124. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +0 -28
  125. data/test/rails/overrides/lib/tasks/rspec.rake +0 -165
  126. data/test/rails/overrides/spec/controllers/filter_spec.rb +0 -159
  127. data/test/rails/overrides/spec/controllers/pc_spec.rb +0 -13
  128. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +0 -42
  129. data/test/rails/overrides/spec/controllers/template_path_spec.rb +0 -117
  130. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +0 -117
  131. data/test/rails/overrides/spec/rspec.rake +0 -165
  132. data/test/rails/overrides/spec/spec.opts +0 -4
@@ -1,17 +1,27 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # desc "Explaining what the task does"
2
3
  # task :jpmobile do
3
4
  # # Task goes here
4
5
  # end
5
6
 
6
7
  begin
7
- require 'spec'
8
- require 'spec/rake/spectask'
8
+ require 'rspec/core/rake_task'
9
+
9
10
  namespace :spec do
10
11
  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')]
12
+ RSpec::Core::RakeTask.new(:unit) do |t|
13
+ spec_dir = File.join(File.dirname(__FILE__), '../../', 'spec')
14
+ # t.spec_opts = File.read(File.join(spec_dir, 'spec.opts')).split
15
+ # t.spec_files = FileList[File.join(spec_dir, 'unit', '**', '*_spec.rb')]
16
+ t.pattern = "#{spec_dir}/unit/*_spec.rb"
17
+ end
18
+
19
+ desc 'run rack testing'
20
+ RSpec::Core::RakeTask.new(:rack) do |t|
21
+ spec_dir = File.join(File.dirname(__FILE__), '../../', 'spec')
22
+ # t.spec_opts = File.read(File.join(spec_dir, 'spec.opts')).split
23
+ # t.spec_files = FileList[File.join(spec_dir, 'rack', '**', '*_spec.rb')]
24
+ t.pattern = "#{spec_dir}/rack/**/*_spec.rb"
15
25
  end
16
26
  end
17
27
  rescue LoadError
@@ -29,7 +39,7 @@ namespace :test do
29
39
  task :rails, [:versions] do |t, args|
30
40
  rails_root = "test/rails/rails_root"
31
41
  relative_root = "../../../"
32
- rails_versions = args.versions.split("/") rescue ["2.3.8"]
42
+ rails_versions = args.versions.split("/") rescue ["3.0.0.rc"]
33
43
 
34
44
  puts "Running tests in Rails #{rails_versions.join(', ')}"
35
45
 
@@ -38,7 +48,7 @@ namespace :test do
38
48
  # generate rails app
39
49
  FileUtils.rm_rf(rails_root)
40
50
  FileUtils.mkdir_p(rails_root)
41
- system "rails _#{rails_version}_ --force #{rails_root}"
51
+ system "rails new #{rails_root}"
42
52
 
43
53
  # setup jpmobile
44
54
  plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile')
@@ -60,20 +70,29 @@ namespace :test do
60
70
  end
61
71
 
62
72
  # for cookie_only option
63
- config_path = File.join(rails_root, 'config', 'environment.rb')
64
- File.open(config_path, 'a') do |file|
73
+ config_path = File.join(rails_root, 'config', 'initializers', 'session_store.rb')
74
+ File.open(config_path, 'w') do |file|
65
75
  file.write <<-END
66
-
67
- ActionController::Base.session = {:key => "_session_id", :cookie_only => false}
76
+ Rails.application.config.session_store :active_record_store, :key => '_session_id'
77
+ Rails.application.config.session_options = {:cookie_only => false}
68
78
  END
69
79
  end
70
80
 
71
81
  # run tests in rails
72
82
  cd rails_root
73
- ruby "-S rake db:migrate"
83
+ # ruby "-S bundle install"
84
+ ruby "-S rake db:migrate test"
74
85
  ruby "-S rake spec"
86
+ # ruby "-S rspec -b --color spec/requests/trans_sid_spec.rb"
75
87
 
76
88
  cd relative_root
77
89
  end
78
90
  end
91
+ desc "Run sinatra on jpmobile tests"
92
+ Rake::TestTask.new(:sinatra) do |t|
93
+ t.libs << 'lib'
94
+ t.libs << 'test/sinatra'
95
+ t.pattern = 'test/sinatra/test/*_test.rb'
96
+ t.verbose = true
97
+ end
79
98
  end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
3
+
4
+ describe Jpmobile::Rack::MobileCarrier, "android" do
5
+ include Rack::Test::Methods
6
+
7
+ context "端末種別で" do
8
+ it "Android を判別できること" do
9
+ res = Rack::MockRequest.env_for(
10
+ 'http://jpmobile-rails.org/',
11
+ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1')
12
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
13
+
14
+ env['rack.jpmobile'].class.should == Jpmobile::Mobile::Android
15
+ env['rack.jpmobile'].position.should be_nil
16
+ env['rack.jpmobile'].smart_phone?.should be_true
17
+ env['rack.jpmobile'].supports_cookie?.should be_true
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,206 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
3
+
4
+ describe Jpmobile::Rack::MobileCarrier, "au" do
5
+ include Rack::Test::Methods
6
+
7
+ context "端末種別で" do
8
+ it "KDDI-CA32 で判別できること" do
9
+ res = Rack::MockRequest.env_for(
10
+ 'http://jpmobile-rails.org/',
11
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
12
+ "HTTP_X_UP_SUBNO" => "00000000000000_mj.ezweb.ne.jp")
13
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
14
+
15
+ env['rack.jpmobile'].class.should == Jpmobile::Mobile::Au
16
+ env['rack.jpmobile'].subno.should == "00000000000000_mj.ezweb.ne.jp"
17
+ env['rack.jpmobile'].ident.should == "00000000000000_mj.ezweb.ne.jp"
18
+ env['rack.jpmobile'].ident_subscriber.should == "00000000000000_mj.ezweb.ne.jp"
19
+
20
+ env['rack.jpmobile'].position.should be_nil
21
+ env['rack.jpmobile'].supports_cookie?.should be_true
22
+ end
23
+
24
+ it "TK22 で判別できること" do
25
+ res = Rack::MockRequest.env_for(
26
+ 'http://jpmobile-rails.org/',
27
+ 'HTTP_USER_AGENT' => "UP.Browser/3.04-KCTA UP.Link/3.4.5.9")
28
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
29
+
30
+ env['rack.jpmobile'].class.should == Jpmobile::Mobile::Au
31
+ end
32
+ end
33
+
34
+ context "GPS で" do
35
+ it "緯度経度を取得できること(dgree)" do
36
+ res = Rack::MockRequest.env_for(
37
+ 'http://jpmobile-rails.org/',
38
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
39
+ "QUERY_STRING" => "ver=1&datum=0&unit=1&lat=%2b43.07772&lon=%2b141.34114&alt=64&time=20061016192415&smaj=69&smin=18&vert=21&majaa=115&fm=1")
40
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
41
+
42
+ env['rack.jpmobile'].position.lat.should == 43.07772
43
+ env['rack.jpmobile'].position.lon.should == 141.34114
44
+ end
45
+
46
+ it "緯度経度を取得できること(dms)" do
47
+ res = Rack::MockRequest.env_for(
48
+ 'http://jpmobile-rails.org/',
49
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
50
+ "QUERY_STRING" => "ver=1&datum=0&unit=0&lat=%2b43.05.08.95&lon=%2b141.20.25.99&alt=155&time=20060521010328&smaj=76&smin=62&vert=65&majaa=49&fm=1")
51
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
52
+
53
+ env['rack.jpmobile'].position.lat.should be_close(43.08581944, 1e-7)
54
+ env['rack.jpmobile'].position.lon.should be_close(141.3405528, 1e-7)
55
+ end
56
+
57
+ it "緯度経度を取得できること(dgree_tokyo)" do
58
+ res = Rack::MockRequest.env_for(
59
+ 'http://jpmobile-rails.org/',
60
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
61
+ "QUERY_STRING" => "ver=1&datum=1&unit=1&lat=%2b43.07475&lon=%2b141.34259&alt=8&time=20061017182825&smaj=113&smin=76&vert=72&majaa=108&fm=1")
62
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
63
+
64
+ env['rack.jpmobile'].position.lat.should be_close(43.07719289, 1e-4)
65
+ env['rack.jpmobile'].position.lon.should be_close(141.3389013, 1e-4)
66
+ end
67
+
68
+ it "緯度経度を取得できること(dgree_tokyo)" do
69
+ res = Rack::MockRequest.env_for(
70
+ 'http://jpmobile-rails.org/',
71
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
72
+ "QUERY_STRING" => "ver=1&datum=1&unit=1&lat=%2b43.07475&lon=%2b141.34259&alt=8&time=20061017182825&smaj=113&smin=76&vert=72&majaa=108&fm=1")
73
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
74
+
75
+ env['rack.jpmobile'].position.lat.should be_close(43.07719289, 1e-4)
76
+ env['rack.jpmobile'].position.lon.should be_close(141.3389013, 1e-4)
77
+ end
78
+
79
+ it "緯度経度を取得できること(dms_tokyo)" do
80
+ res = Rack::MockRequest.env_for(
81
+ 'http://jpmobile-rails.org/',
82
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
83
+ "QUERY_STRING" => "datum=tokyo&unit=dms&lat=43.04.55.00&lon=141.20.50.75")
84
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
85
+
86
+ env['rack.jpmobile'].position.lat.should be_close(43.08194444, 1e-7)
87
+ env['rack.jpmobile'].position.lon.should be_close(141.3474306, 1e-7)
88
+ end
89
+
90
+ it "緯度経度を取得できること(antenna)" do
91
+ res = Rack::MockRequest.env_for(
92
+ 'http://jpmobile-rails.org/',
93
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
94
+ "QUERY_STRING" => "datum=tokyo&unit=dms&lat=43.04.55.00&lon=141.20.50.75")
95
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
96
+
97
+ env['rack.jpmobile'].position.lat.should be_close(43.08194444, 1e-7)
98
+ env['rack.jpmobile'].position.lon.should be_close(141.3474306, 1e-7)
99
+ end
100
+
101
+ it "GeoKit がある場合に取得できること" do
102
+ res = Rack::MockRequest.env_for(
103
+ 'http://jpmobile-rails.org/',
104
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
105
+ "QUERY_STRING" => "ver=1&datum=0&unit=1&lat=%2b43.07772&lon=%2b141.34114&alt=64&time=20061016192415&smaj=69&smin=18&vert=21&majaa=115&fm=1")
106
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
107
+
108
+ env['rack.jpmobile'].position.lat.should == 43.07772
109
+ env['rack.jpmobile'].position.lon.should == 141.34114
110
+ env['rack.jpmobile'].position.ll.should == "43.07772,141.34114"
111
+ if env['rack.jpmobile'].position.respond_to?(:distance_to) # GeoKit method
112
+ env['rack.jpmobile'].position.distance_to(env['rack.jpmobile'].position).should == 0
113
+ end
114
+ end
115
+
116
+ context "古い機種での取得可否で" do
117
+ it "W31CA を判定できること" do
118
+ res = Rack::MockRequest.env_for(
119
+ 'http://jpmobile-rails.org/',
120
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
121
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
122
+
123
+ env['rack.jpmobile'].device_id.should == "CA32"
124
+ env['rack.jpmobile'].supports_location?.should be_true
125
+ env['rack.jpmobile'].supports_gps?.should be_true
126
+ end
127
+
128
+ it "A1402S を判定できること" do
129
+ res = Rack::MockRequest.env_for(
130
+ 'http://jpmobile-rails.org/',
131
+ 'HTTP_USER_AGENT' => "KDDI-SN26 UP.Browser/6.2.0.6.2 (GUI) MMP/2.0")
132
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
133
+
134
+ env['rack.jpmobile'].device_id.should == "SN26"
135
+ env['rack.jpmobile'].supports_location?.should be_true
136
+ env['rack.jpmobile'].supports_gps?.should be_false
137
+ end
138
+
139
+ it "TK22 を判定できること" do
140
+ res = Rack::MockRequest.env_for(
141
+ 'http://jpmobile-rails.org/',
142
+ 'HTTP_USER_AGENT' => "UP.Browser/3.04-KCTA UP.Link/3.4.5.9")
143
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
144
+
145
+ env['rack.jpmobile'].device_id.should == "KCTA"
146
+ env['rack.jpmobile'].supports_location?.should be_false
147
+ env['rack.jpmobile'].supports_gps?.should be_false
148
+ end
149
+ end
150
+ end
151
+
152
+ context "IPアドレス制限で" do
153
+ it "正しいIPアドレス空間からのアクセスを判断できること" do
154
+ res = Rack::MockRequest.env_for(
155
+ 'http://jpmobile-rails.org/',
156
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
157
+ "REMOTE_ADDR" => "210.230.128.225")
158
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
159
+
160
+ env['rack.jpmobile'].valid_ip?.should be_true
161
+ end
162
+
163
+ it "正しくないIPアドレス空間からのアクセスを判断できること" do
164
+ res = Rack::MockRequest.env_for(
165
+ 'http://jpmobile-rails.org/',
166
+ 'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
167
+ "REMOTE_ADDR" => "127.0.0.1")
168
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
169
+
170
+ env['rack.jpmobile'].valid_ip?.should be_false
171
+ end
172
+ end
173
+
174
+ context "画面情報で" do
175
+ it "端末の画面サイズを正しく取得できること" do
176
+ res = Rack::MockRequest.env_for(
177
+ 'http://jpmobile-rails.org/',
178
+ 'HTTP_USER_AGENT' => "KDDI-CA33 UP.Browser/6.2.0.10.4 (GUI) MMP/2.0",
179
+ "HTTP_X_UP_DEVCAP_SCREENDEPTH" => "16,RGB565",
180
+ "HTTP_X_UP_DEVCAP_SCREENPIXELS" => "240,346",
181
+ "HTTP_X_UP_DEVCAP_ISCOLOR" => "1")
182
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
183
+
184
+ env['rack.jpmobile'].display.width.should == 240
185
+ env['rack.jpmobile'].display.height.should == 346
186
+ env['rack.jpmobile'].display.color?.should be_true
187
+ env['rack.jpmobile'].display.colors.should == 65536
188
+ end
189
+
190
+ it "端末の画面情報が渡ってない場合に正しく動作すること" do
191
+ res = Rack::MockRequest.env_for(
192
+ 'http://jpmobile-rails.org/',
193
+ 'HTTP_USER_AGENT' => "KDDI-CA33 UP.Browser/6.2.0.10.4 (GUI) MMP/2.0")
194
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
195
+
196
+ env['rack.jpmobile'].display.width.should be_nil
197
+ env['rack.jpmobile'].display.height.should be_nil
198
+ env['rack.jpmobile'].display.browser_width.should be_nil
199
+ env['rack.jpmobile'].display.browser_height.should be_nil
200
+ env['rack.jpmobile'].display.physical_width.should be_nil
201
+ env['rack.jpmobile'].display.physical_height.should be_nil
202
+ env['rack.jpmobile'].display.color?.should be_nil
203
+ env['rack.jpmobile'].display.colors.should be_nil
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,237 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../../rack_helper.rb')
3
+
4
+ describe Jpmobile::Rack::MobileCarrier, "docomo" do
5
+ include Rack::Test::Methods
6
+
7
+ context "SH902i のとき" do
8
+ before(:each) do
9
+ res = Rack::MockRequest.env_for(
10
+ 'http://jpmobile-rails.org/',
11
+ 'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH902i(c100;TB;W24H16)')
12
+ @env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
13
+ end
14
+
15
+ it "Jpmobile::Mobile::Docomo のインスタンスが env['rack.mobile'] にあること" do
16
+ @env['rack.jpmobile'].class.should == Jpmobile::Mobile::Docomo
17
+ end
18
+
19
+ it "#position などが nil になること" do
20
+ @env['rack.jpmobile'].position.should be_nil
21
+ @env['rack.jpmobile'].areacode.should be_nil
22
+ @env['rack.jpmobile'].serial_number.should be_nil
23
+ @env['rack.jpmobile'].icc.should be_nil
24
+ @env['rack.jpmobile'].ident.should be_nil
25
+ @env['rack.jpmobile'].ident_device.should be_nil
26
+ @env['rack.jpmobile'].ident_subscriber.should be_nil
27
+ end
28
+
29
+ it "#supports_cookie? などが false になること" do
30
+ @env['rack.jpmobile'].supports_cookie?.should be_false
31
+ end
32
+
33
+ it "#imode_browser_versionが1.0になること" do
34
+ @env['rack.jpmobile'].imode_browser_version.should == '1.0'
35
+ end
36
+ end
37
+
38
+ context "SO506iC のとき" do
39
+ before(:each) do
40
+ res = Rack::MockRequest.env_for(
41
+ 'http://jpmobile-rails.org/',
42
+ 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO506iC/c20/TB/W20H10")
43
+ @env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
44
+ end
45
+
46
+ it "Jpmobile::Mobile::Docomo のインスタンスが env['rack.mobile'] にあること" do
47
+ @env['rack.jpmobile'].class.should == Jpmobile::Mobile::Docomo
48
+ end
49
+
50
+ it "#position などが nil になること" do
51
+ @env['rack.jpmobile'].position.should be_nil
52
+ @env['rack.jpmobile'].areacode.should be_nil
53
+ @env['rack.jpmobile'].serial_number.should be_nil
54
+ @env['rack.jpmobile'].icc.should be_nil
55
+ @env['rack.jpmobile'].ident.should be_nil
56
+ @env['rack.jpmobile'].ident_device.should be_nil
57
+ @env['rack.jpmobile'].ident_subscriber.should be_nil
58
+ end
59
+
60
+ it "#supports_cookie? などが false になること" do
61
+ @env['rack.jpmobile'].supports_cookie?.should be_false
62
+ end
63
+
64
+ it "#imode_browser_versionが1.0になること" do
65
+ @env['rack.jpmobile'].imode_browser_version.should == '1.0'
66
+ end
67
+ end
68
+
69
+ context "P09A3で" do
70
+ before(:each) do
71
+ res = Rack::MockRequest.env_for(
72
+ 'http://jpmobile-rails.org/',
73
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 P09A3(c500;TB;W20H12)")
74
+ @env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
75
+ end
76
+
77
+ it "#supports_cookie? が true になること" do
78
+ @env['rack.jpmobile'].supports_cookie?.should be_true
79
+ end
80
+
81
+ it "#imode_browser_versionが2.0になること" do
82
+ @env['rack.jpmobile'].imode_browser_version.should == '2.0'
83
+ end
84
+ end
85
+
86
+ context "P07A3で" do
87
+ before(:each) do
88
+ res = Rack::MockRequest.env_for(
89
+ 'http://jpmobile-rails.org/',
90
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 P07A3(c500;TB;W24H15)")
91
+ @env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
92
+ end
93
+
94
+ it "#supports_cookie? が true になること" do
95
+ @env['rack.jpmobile'].supports_cookie?.should be_true
96
+ end
97
+
98
+ it "#imode_browser_versionが2.0になること" do
99
+ @env['rack.jpmobile'].imode_browser_version.should == '2.0'
100
+ end
101
+ end
102
+
103
+ context "L01Bで" do
104
+ before(:each) do
105
+ res = Rack::MockRequest.env_for(
106
+ 'http://jpmobile-rails.org/',
107
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 L01B(c500;TB;W40H10)")
108
+ @env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
109
+ end
110
+
111
+ it "#supports_cookie? が true になること" do
112
+ @env['rack.jpmobile'].supports_cookie?.should be_true
113
+ end
114
+
115
+ it "#imode_browser_versionが2.0になること" do
116
+ @env['rack.jpmobile'].imode_browser_version.should == '2.0LE'
117
+ end
118
+ end
119
+
120
+ context "iエリアで" do
121
+ it "データが取得できること" do
122
+ res = Rack::MockRequest.env_for(
123
+ 'http://jpmobile-rails.org/',
124
+ 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO506iC/c20/TB/W20H10",
125
+ "QUERY_STRING" => "AREACODE=00100&ACTN=OK")
126
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
127
+
128
+ env['rack.jpmobile'].areacode.should == "00100"
129
+ end
130
+
131
+ it "位置情報も取得できること" do
132
+ res = Rack::MockRequest.env_for(
133
+ 'http://jpmobile-rails.org/',
134
+ 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO506iC/c20/TB/W20H10",
135
+ "QUERY_STRING" => "LAT=%2B35.00.35.600&LON=%2B135.41.35.600&GEO=wgs84&POSINFO=2&AREACODE=00100&ACTN=OK")
136
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
137
+
138
+ env['rack.jpmobile'].areacode.should == "00100"
139
+
140
+ env['rack.jpmobile'].position.lat.should be_close(35.00988889, 1e-7)
141
+ env['rack.jpmobile'].position.lon.should be_close(135.6932222, 1e-7)
142
+ end
143
+ end
144
+
145
+ context "GPS で" do
146
+ it "位置が取得できること" do
147
+ res = Rack::MockRequest.env_for(
148
+ 'http://jpmobile-rails.org/',
149
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 SA702i(c100;TB;W30H15)",
150
+ "QUERY_STRING" => "lat=%2B35.00.35.600&lon=%2B135.41.35.600&geo=wgs84&x-acc=3")
151
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
152
+
153
+ env['rack.jpmobile'].position.lat.should be_close(35.00988889, 1e-7)
154
+ env['rack.jpmobile'].position.lon.should be_close(135.6932222, 1e-7)
155
+ end
156
+
157
+ # DoCoMo, 903i, GPS
158
+ # "WGS84"が大文字。altで高度が取得できているようだ。どちらも仕様書には記述がない。
159
+ # http://www.nttdocomo.co.jp/service/imode/make/content/html/outline/gps.html
160
+ it "903iでは高度があるが、正確にデータが取得できること" do
161
+ res = Rack::MockRequest.env_for(
162
+ 'http://jpmobile-rails.org/',
163
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 SH903i(c100;TB;W24H16)",
164
+ "QUERY_STRING" => "lat=%2B35.00.35.600&lon=%2B135.41.35.600&geo=WGS84&alt=%2B64.000&x-acc=1")
165
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
166
+
167
+ env['rack.jpmobile'].position.lat.should be_close(35.00988889, 1e-7)
168
+ env['rack.jpmobile'].position.lon.should be_close(135.6932222, 1e-7)
169
+ end
170
+ end
171
+
172
+ context "端末番号が" do
173
+ it "mova で取得できること" do
174
+ res = Rack::MockRequest.env_for(
175
+ 'http://jpmobile-rails.org/',
176
+ 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO505iS/c20/TC/W30H16/serXXXXX000000")
177
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
178
+
179
+ env['rack.jpmobile'].serial_number.should == "XXXXX000000"
180
+ env['rack.jpmobile'].ident.should == "XXXXX000000"
181
+ env['rack.jpmobile'].icc.should be_nil
182
+ env['rack.jpmobile'].ident_device.should == "XXXXX000000"
183
+ env['rack.jpmobile'].ident_subscriber.should be_nil
184
+ end
185
+
186
+ it "FOMA で取得できること" do
187
+ res = Rack::MockRequest.env_for(
188
+ 'http://jpmobile-rails.org/',
189
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 D902i(c100;TB;W23H16;ser999999999999999;icc0000000000000000000f)")
190
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
191
+
192
+ env['rack.jpmobile'].serial_number.should == "999999999999999"
193
+ env['rack.jpmobile'].icc.should == "0000000000000000000f"
194
+ env['rack.jpmobile'].ident.should == "0000000000000000000f"
195
+ env['rack.jpmobile'].ident_device.should == "999999999999999"
196
+ env['rack.jpmobile'].ident_subscriber.should == "0000000000000000000f"
197
+ end
198
+ end
199
+
200
+ context "IPアドレス制限で" do
201
+ it "正しいIPアドレス空間からのアクセスを判断できること" do
202
+ res = Rack::MockRequest.env_for(
203
+ 'http://jpmobile-rails.org/',
204
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 SH902i(c100;TB;W24H12)",
205
+ "REMOTE_ADDR" => "210.153.84.1")
206
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
207
+
208
+ env['rack.jpmobile'].valid_ip?.should be_true
209
+ end
210
+
211
+ it "正しくないIPアドレス空間からのアクセスを判断できること" do
212
+ res = Rack::MockRequest.env_for(
213
+ 'http://jpmobile-rails.org/',
214
+ 'HTTP_USER_AGENT' => "DoCoMo/2.0 SH902i(c100;TB;W24H12)",
215
+ "REMOTE_ADDR" => "127.0.0.1")
216
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
217
+
218
+ env['rack.jpmobile'].valid_ip?.should be_false
219
+ end
220
+ end
221
+
222
+ context "端末サイズ" do
223
+ it "SO506iCのサイズを適切に取得できること" do
224
+ res = Rack::MockRequest.env_for(
225
+ 'http://jpmobile-rails.org/',
226
+ 'HTTP_USER_AGENT' => "DoCoMo/1.0/SO506iC/c20/TB/W20H10")
227
+ env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
228
+
229
+ env['rack.jpmobile'].display.browser_width.should == 240
230
+ env['rack.jpmobile'].display.browser_height.should == 256
231
+ env['rack.jpmobile'].display.width.should == 240
232
+ env['rack.jpmobile'].display.height.should == 256
233
+ env['rack.jpmobile'].display.color?.should be_true
234
+ env['rack.jpmobile'].display.colors.should == 262144
235
+ end
236
+ end
237
+ end