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
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe "PCからのアクセスの場合" do
6
+ before do
7
+ @headers = {
8
+ "HTTP_USER_AGENT" => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)",
9
+ }
10
+ end
11
+
12
+ it "request.mobile は nil であるべき" do
13
+ get "/mobile_spec/index", {}, @headers
14
+
15
+ request.mobile.should be_nil
16
+ end
17
+ it "request.mobile? は false であるべき" do
18
+ get "/mobile_spec/index", {}, @headers
19
+
20
+ request.mobile?.should be_false
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe "Softbank Emulator からのアクセスのとき" do
6
+ it "request.mobile は Softbank のインスタンスであること" do
7
+ get "/mobile_spec/index", {}, {"HTTP_USER_AGENT" => "Semulator"}
8
+
9
+ request.mobile.should be_an_instance_of(Jpmobile::Mobile::Softbank)
10
+ request.mobile?.should be_true
11
+ end
12
+ end
13
+
14
+ describe "Vodafone Emulator からのアクセスのとき" do
15
+ it "request.mobile は Vodafone のインスタンスであること" do
16
+ get "/mobile_spec/index", {}, {"HTTP_USER_AGENT" => "Vemulator"}
17
+
18
+ request.mobile.should be_an_instance_of(Jpmobile::Mobile::Vodafone)
19
+ request.mobile?.should be_true
20
+ end
21
+ end
@@ -0,0 +1,234 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ #
6
+ # 携帯からのアクセス
7
+ #
8
+ describe TemplatePathController, "DoCoMo SH902i からのアクセス" do
9
+ before do
10
+ @user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
11
+ end
12
+
13
+ it 'テンプレートの探索順が正しいこと' do
14
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
15
+
16
+ controller.view_paths.mobile_template_candidates.should == [ 'mobile_docomo', 'mobile' ]
17
+ end
18
+ end
19
+
20
+ describe TemplatePathController, "au CA32 からのアクセス" do
21
+ before do
22
+ @user_agent = "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
23
+ end
24
+ it 'テンプレートの探索順が正しいこと' do
25
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
26
+
27
+ controller.view_paths.mobile_template_candidates.should == [ 'mobile_au', 'mobile' ]
28
+ end
29
+ end
30
+
31
+ describe TemplatePathController, "Vodafone V903T からのアクセス" do
32
+ before do
33
+ @user_agent = "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0"
34
+ end
35
+ it 'テンプレートの探索順が正しいこと' do
36
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
37
+
38
+ controller.view_paths.mobile_template_candidates.should == [ 'mobile_vodafone', 'mobile_softbank', 'mobile' ]
39
+ end
40
+ end
41
+
42
+ describe TemplatePathController, "SoftBank 910T からのアクセス" do
43
+ before do
44
+ @user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
45
+ end
46
+ it 'テンプレートの探索順が正しいこと' do
47
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
48
+
49
+ controller.view_paths.mobile_template_candidates.should == [ 'mobile_softbank', 'mobile' ]
50
+ end
51
+ end
52
+
53
+ describe TemplatePathController, "iPhone からのアクセス" do
54
+ before do
55
+ @user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'
56
+ end
57
+ it 'テンプレートの探索順が正しいこと' do
58
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
59
+
60
+ controller.view_paths.mobile_template_candidates.should == [ 'smart_phone_iphone', 'smart_phone' ]
61
+ end
62
+ end
63
+
64
+ describe TemplatePathController, "Android からのアクセス" do
65
+ before do
66
+ @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'
67
+ end
68
+ it 'テンプレートの探索順が正しいこと' do
69
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
70
+
71
+ controller.view_paths.mobile_template_candidates.should == [ 'smart_phone_android', 'smart_phone' ]
72
+ end
73
+ end
74
+
75
+ describe TemplatePathController, "Windows Phone からのアクセス" do
76
+ before do
77
+ @user_agent = 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)'
78
+ end
79
+ it 'テンプレートの探索順が正しいこと' do
80
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
81
+
82
+ controller.view_paths.mobile_template_candidates.should == [ 'smart_phone_windows_phone', 'smart_phone' ]
83
+ end
84
+ end
85
+
86
+ describe TemplatePathController, "integrated_views" do
87
+ describe "index" do
88
+ context "PCからのアクセスの場合" do
89
+ before do
90
+ @user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)"
91
+ end
92
+ it 'index.html.erbが使用されること' do
93
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
94
+
95
+ response.should have_tag("h1", :content => "index.html.erb")
96
+ end
97
+ end
98
+
99
+ context "DoCoMoからのアクセスの場合" do
100
+ before do
101
+ @user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
102
+ end
103
+ it 'index_mobile_docomo.html.erbが使用されること' do
104
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
105
+
106
+ response.should have_tag("h1", :content => "index_mobile_docomo.html.erb")
107
+ end
108
+
109
+ it 'show.html.erb がなくとも show_mobile_docomo.html.erbが使用されること' do
110
+ get "/template_path/show", {}, { "HTTP_USER_AGENT" => @user_agent}
111
+
112
+ response.should have_tag("h1", :content => "show_mobile_docomo.html.erb")
113
+ end
114
+ end
115
+
116
+ context "SoftBankからのアクセスの場合" do
117
+ before do
118
+ @user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
119
+ end
120
+ it 'index_mobile.html.erbが使用されること' do
121
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
122
+
123
+ response.should have_tag("h1", :content => "index_mobile.html.erb")
124
+ end
125
+
126
+ it 'show.html.erb がなくとも show_mobile.html.erbが使用されること' do
127
+ get "/template_path/show", {}, { "HTTP_USER_AGENT" => @user_agent}
128
+
129
+ response.should have_tag("h1", :content => "show_mobile.html.erb")
130
+ end
131
+ end
132
+
133
+ context "iPhoneからのアクセスの場合" do
134
+ before do
135
+ @user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'
136
+ end
137
+ it 'smart_phone_iphone.html.erbが使用されること' do
138
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
139
+
140
+ response.should have_tag("h1", :content => "smart_phone_iphone.html.erb")
141
+ end
142
+ end
143
+
144
+ context "Androidからのアクセスの場合" do
145
+ before do
146
+ @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'
147
+ end
148
+ it 'smart_phone.html.erbが使用されること' do
149
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
150
+
151
+ response.should have_tag("h1", :content => "smart_phone.html.erb")
152
+ end
153
+ end
154
+
155
+ context "Windows Phoneからのアクセスの場合" do
156
+ before do
157
+ @user_agent = 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)'
158
+ end
159
+ it 'smart_phone.html.erbが使用されること' do
160
+ get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
161
+
162
+ response.should have_tag("h1", :content => "smart_phone.html.erb")
163
+ end
164
+ end
165
+ end
166
+
167
+ context "partial" do
168
+ context "PCからのアクセスの場合" do
169
+ before do
170
+ @user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)"
171
+ end
172
+ it '_partial.html.erbが使用されること' do
173
+ get "/template_path/partial", {}, { "HTTP_USER_AGENT" => @user_agent}
174
+
175
+ response.should have_tag("h2", :content => "_partial.html.erb")
176
+ end
177
+ end
178
+
179
+ context "DoCoMoからのアクセスの場合" do
180
+ before do
181
+ @user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
182
+ end
183
+ it '_partial_mobile_docomo.html.erbが使用されること' do
184
+ get "/template_path/partial", {}, { "HTTP_USER_AGENT" => @user_agent}
185
+
186
+ response.should have_tag("h2", :content => "_partial_mobile_docomo.html.erb")
187
+ end
188
+ end
189
+
190
+ context "SoftBankからのアクセスの場合" do
191
+ before do
192
+ @user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
193
+ end
194
+ it '_partial_mobile.html.erbが使用されること' do
195
+ get "/template_path/partial", {}, { "HTTP_USER_AGENT" => @user_agent}
196
+
197
+ response.should have_tag("h2", :content => "_partial_mobile.html.erb")
198
+ end
199
+ end
200
+
201
+ context "iPhoneからのアクセスの場合" do
202
+ before do
203
+ @user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'
204
+ end
205
+ it '_partial_smart_phone_iphone.html.erbが使用されること' do
206
+ get "/template_path/partial", {}, { "HTTP_USER_AGENT" => @user_agent}
207
+
208
+ response.should have_tag("h2", :content => "_partial_smart_phone_iphone.html.erb")
209
+ end
210
+ end
211
+
212
+ context "Androidからのアクセスの場合" do
213
+ before do
214
+ @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'
215
+ end
216
+ it '_partial_smart_phone.html.erbが使用されること' do
217
+ get "/template_path/partial", {}, { "HTTP_USER_AGENT" => @user_agent}
218
+
219
+ response.should have_tag("h2", :content => "_partial_smart_phone.html.erb")
220
+ end
221
+ end
222
+
223
+ context "Windows Phoneからのアクセスの場合" do
224
+ before do
225
+ @user_agent = 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)'
226
+ end
227
+ it '_partial_smart_phone.html.erbが使用されること' do
228
+ get "/template_path/partial", {}, { "HTTP_USER_AGENT" => @user_agent}
229
+
230
+ response.should have_tag("h2", :content => "_partial_smart_phone.html.erb")
231
+ end
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,142 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ def get_with_session(controller, action, user_agent)
6
+ open_session do |sess|
7
+ sess.get "/#{controller}/#{action}", {}, {"HTTP_USER_AGENT" => user_agent}
8
+ end
9
+ end
10
+
11
+ shared_examples_for "trans_sid が起動しないとき" do
12
+ it "で link_to の自動書き換えが行われない" do
13
+ res = get_with_session(@controller, "link", @user_agent)
14
+
15
+ res.response.body.should =~ /<a href=\"\/.+?\/link\">linkto<\/a>/
16
+ end
17
+ it "で form の自動書き換えが行われない" do
18
+ res = get_with_session(@controller, "form", @user_agent)
19
+
20
+ res.response.body.should =~ /<form action=\"\/.+?\/form\"/
21
+ end
22
+ it "で redirect の自動書き換えが行われない" do
23
+ res = get_with_session(@controller, "redirect", @user_agent)
24
+
25
+ res.response.header['Location'] =~ /\/$/
26
+ end
27
+ end
28
+
29
+ shared_examples_for "trans_sid が起動するとき" do
30
+ it "で link_to の自動書き換えが行われる" do
31
+ res = get_with_session(@controller, "link", @user_agent)
32
+
33
+ res.response.body.should =~ /<a href=\"\/.+?\/link\?_session_id=[a-zA-Z0-9]{32}\">linkto<\/a>/
34
+ end
35
+ it "で form の自動書き換えが行われる" do
36
+ res = get_with_session(@controller, "form", @user_agent)
37
+
38
+ res.response.body.should =~ /<form action=\"\/.+?\/form\?_session_id=[a-zA-Z0-9]{32}\"/
39
+ end
40
+ it "で redirect の自動書き換えが行われる" do
41
+ res = get_with_session(@controller, "redirect", @user_agent)
42
+
43
+ res.response.header['Location'] =~ /\?_session_id=[a-zA-Z0-9]{32}$/
44
+ end
45
+ end
46
+
47
+ describe TransSidBaseController, "という trans_sid が有効になっていないコントローラ" do
48
+ before(:each) do
49
+ @controller = "trans_sid_base"
50
+ @user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"
51
+ end
52
+
53
+ it "の trans_sid_mode は nil" do
54
+ get "/#{@controller}/link", {}, {"HTTP_USER_AGENT" => @user_agent}
55
+
56
+ controller.trans_sid_mode.should be_nil
57
+ end
58
+ it_should_behave_like "trans_sid が起動しないとき"
59
+ end
60
+
61
+ describe TransSidNoneController, "という trans_sid :none が指定されているコントローラ" do
62
+ before(:each) do
63
+ @controller = "trans_sid_none"
64
+ @user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"
65
+ end
66
+
67
+ it "の trans_sid_mode は :none" do
68
+ get "/#{@controller}/link", {}, {"HTTP_USER_AGENT" => @user_agent}
69
+
70
+ controller.trans_sid_mode.should == :none
71
+ end
72
+ it_should_behave_like "trans_sid が起動しないとき"
73
+ end
74
+
75
+ describe TransSidAlwaysController, "という trans_sid :always が指定されているコントローラ" do
76
+ before(:each) do
77
+ @controller = "trans_sid_always"
78
+ @user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"
79
+ end
80
+
81
+ it "の trans_sid_mode は :always" do
82
+ get "/#{@controller}/link", {}, {"HTTP_USER_AGENT" => @user_agent}
83
+
84
+ controller.trans_sid_mode.should == :always
85
+ end
86
+ it_should_behave_like "trans_sid が起動するとき"
87
+ end
88
+
89
+ describe TransSidMobileController, "という trans_sid :mobile が指定されているコントローラ" do
90
+ before(:each) do
91
+ @controller = "trans_sid_mobile"
92
+ @user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"
93
+ end
94
+
95
+ it "の trans_sid_mode は :mobile" do
96
+ get "/#{@controller}/link", {}, {"HTTP_USER_AGENT" => @user_agent}
97
+
98
+ controller.trans_sid_mode.should == :mobile
99
+ end
100
+ end
101
+
102
+ def describe_mobile_with_ua(user_agent, &block)
103
+ describe("trans_sid :mobile が指定されているコントローラに #{user_agent} からアクセスしたとき") do
104
+ before(:each) do
105
+ @controller = "trans_sid_mobile"
106
+ @user_agent = user_agent
107
+ end
108
+
109
+ instance_eval(&block)
110
+ end
111
+ end
112
+
113
+ # NOTE: Rails 3.0b4 では session_id が自動的に生成されるようなので、強制的に書き換わってしまう。
114
+ # describe TransSidAlwaysAndSessionOffController, "という trans_sid :always が指定されていて session がロードされていないとき" do
115
+ # before(:each) do
116
+ # @controller = "trans_sid_always_and_session_off"
117
+ # @user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"
118
+ # end
119
+
120
+ # it "の trans_sid_mode は :always" do
121
+ # res = get_with_session(@controller, "link", @user_agent)
122
+
123
+ # res.controller.trans_sid_mode.should == :always
124
+ # end
125
+ # it_should_behave_like "trans_sid が起動しないとき"
126
+ # end
127
+
128
+ describe_mobile_with_ua "DoCoMo/2.0 SH902i(c100;TB;W24H12)" do
129
+ it_should_behave_like "trans_sid が起動するとき"
130
+ end
131
+
132
+ describe_mobile_with_ua "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0" do
133
+ it_should_behave_like "trans_sid が起動しないとき"
134
+ end
135
+
136
+ describe_mobile_with_ua "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1" do
137
+ it_should_behave_like "trans_sid が起動しないとき"
138
+ end
139
+
140
+ describe_mobile_with_ua "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0" do
141
+ it_should_behave_like "trans_sid が起動しないとき"
142
+ end
@@ -1,62 +1,31 @@
1
1
  # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
2
  # from the project root directory.
3
3
  ENV["RAILS_ENV"] ||= 'test'
4
- require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
5
- require 'spec/autorun'
6
- require 'spec/rails'
4
+ require File.expand_path("../../config/environment", __FILE__)
5
+ require 'rspec/rails'
7
6
 
8
- Spec::Runner.configure do |config|
9
- # If you're not using ActiveRecord you should remove these
10
- # lines, delete config/database.yml and disable :active_record
11
- # in your config/boot.rb
12
- config.use_transactional_fixtures = true
13
- config.use_instantiated_fixtures = false
14
- config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
10
 
16
- # == Fixtures
17
- #
18
- # You can declare fixtures for each example_group like this:
19
- # describe "...." do
20
- # fixtures :table_a, :table_b
21
- #
22
- # Alternatively, if you prefer to declare them only once, you can
23
- # do so right here. Just uncomment the next line and replace the fixture
24
- # names with your fixtures.
25
- #
26
- # config.global_fixtures = :table_a, :table_b
27
- #
28
- # If you declare global fixtures, be aware that they will be declared
29
- # for all of your examples, even those that don't use them.
30
- #
31
- # You can also declare which fixtures to use (for example fixtures for test/fixtures):
32
- #
33
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
34
- #
11
+ RSpec.configure do |config|
35
12
  # == Mock Framework
36
13
  #
37
- # RSpec uses it's own mocking framework by default. If you prefer to
38
- # use mocha, flexmock or RR, uncomment the appropriate line:
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
39
15
  #
40
16
  # config.mock_with :mocha
41
17
  # config.mock_with :flexmock
42
18
  # config.mock_with :rr
43
- #
44
- # == Notes
45
- #
46
- # For more information take a look at Spec::Runner::Configuration and Spec::Runner
47
- end
19
+ config.mock_with :rspec
48
20
 
49
- def sjis(ascii_8bit)
50
- if ascii_8bit.respond_to?(:force_encoding)
51
- ascii_8bit.force_encoding("Shift_JIS")
52
- end
53
- ascii_8bit
54
- end
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
55
22
 
56
- def to_sjis(utf8)
57
- if utf8.respond_to?(:encode)
58
- utf8.encode("Shift_JIS")
59
- else
60
- utf8.tosjis
61
- end
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, comment the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+ config.include Webrat::HaveTagMatcher
28
+ config.include Jpmobile::Util
62
29
  end
30
+
31
+ require 'pp'