actionpack 2.2.3 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (264) hide show
  1. data/CHANGELOG +433 -375
  2. data/MIT-LICENSE +1 -1
  3. data/README +21 -75
  4. data/Rakefile +1 -1
  5. data/lib/action_controller.rb +80 -43
  6. data/lib/action_controller/assertions/model_assertions.rb +1 -0
  7. data/lib/action_controller/assertions/response_assertions.rb +43 -16
  8. data/lib/action_controller/assertions/routing_assertions.rb +1 -1
  9. data/lib/action_controller/assertions/selector_assertions.rb +17 -12
  10. data/lib/action_controller/assertions/tag_assertions.rb +1 -4
  11. data/lib/action_controller/base.rb +153 -82
  12. data/lib/action_controller/benchmarking.rb +9 -9
  13. data/lib/action_controller/caching.rb +9 -11
  14. data/lib/action_controller/caching/actions.rb +11 -18
  15. data/lib/action_controller/caching/fragments.rb +28 -20
  16. data/lib/action_controller/caching/pages.rb +13 -15
  17. data/lib/action_controller/caching/sweeping.rb +2 -2
  18. data/lib/action_controller/cgi_ext.rb +0 -1
  19. data/lib/action_controller/cgi_ext/cookie.rb +2 -0
  20. data/lib/action_controller/cgi_process.rb +54 -162
  21. data/lib/action_controller/cookies.rb +13 -25
  22. data/lib/action_controller/dispatcher.rb +43 -122
  23. data/lib/action_controller/failsafe.rb +52 -0
  24. data/lib/action_controller/flash.rb +38 -47
  25. data/lib/action_controller/helpers.rb +13 -9
  26. data/lib/action_controller/http_authentication.rb +203 -23
  27. data/lib/action_controller/integration.rb +126 -70
  28. data/lib/action_controller/layout.rb +36 -39
  29. data/lib/action_controller/middleware_stack.rb +119 -0
  30. data/lib/action_controller/middlewares.rb +13 -0
  31. data/lib/action_controller/mime_responds.rb +19 -4
  32. data/lib/action_controller/mime_type.rb +8 -0
  33. data/lib/action_controller/params_parser.rb +71 -0
  34. data/lib/action_controller/performance_test.rb +0 -1
  35. data/lib/action_controller/polymorphic_routes.rb +36 -30
  36. data/lib/action_controller/reloader.rb +14 -0
  37. data/lib/action_controller/request.rb +107 -499
  38. data/lib/action_controller/request_forgery_protection.rb +7 -39
  39. data/lib/action_controller/rescue.rb +55 -35
  40. data/lib/action_controller/resources.rb +34 -31
  41. data/lib/action_controller/response.rb +99 -57
  42. data/lib/action_controller/rewindable_input.rb +28 -0
  43. data/lib/action_controller/routing.rb +7 -7
  44. data/lib/action_controller/routing/builder.rb +4 -1
  45. data/lib/action_controller/routing/optimisations.rb +1 -1
  46. data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
  47. data/lib/action_controller/routing/route.rb +15 -5
  48. data/lib/action_controller/routing/route_set.rb +82 -35
  49. data/lib/action_controller/routing/segments.rb +35 -0
  50. data/lib/action_controller/session/abstract_store.rb +181 -0
  51. data/lib/action_controller/session/cookie_store.rb +197 -175
  52. data/lib/action_controller/session/mem_cache_store.rb +36 -83
  53. data/lib/action_controller/session_management.rb +26 -134
  54. data/lib/action_controller/streaming.rb +24 -7
  55. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  56. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  57. data/lib/action_controller/test_case.rb +87 -30
  58. data/lib/action_controller/test_process.rb +145 -104
  59. data/lib/action_controller/uploaded_file.rb +44 -0
  60. data/lib/action_controller/url_rewriter.rb +3 -6
  61. data/lib/action_controller/vendor/html-scanner.rb +16 -0
  62. data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
  63. data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
  64. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
  65. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
  66. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
  67. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
  68. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
  69. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
  73. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
  74. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
  75. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
  76. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
  77. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
  78. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
  79. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
  80. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
  81. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
  82. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
  83. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
  84. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
  85. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
  86. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
  87. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
  93. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
  94. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
  95. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
  96. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
  97. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
  98. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
  99. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
  100. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
  101. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
  102. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
  103. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
  104. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
  105. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
  106. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
  107. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
  108. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
  109. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
  110. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
  111. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
  112. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
  113. data/lib/action_controller/verification.rb +1 -1
  114. data/lib/action_pack.rb +1 -1
  115. data/lib/action_pack/version.rb +2 -2
  116. data/lib/action_view.rb +22 -17
  117. data/lib/action_view/base.rb +53 -79
  118. data/lib/action_view/erb/util.rb +38 -0
  119. data/lib/action_view/helpers.rb +24 -5
  120. data/lib/action_view/helpers/active_record_helper.rb +2 -2
  121. data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
  122. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  123. data/lib/action_view/helpers/benchmark_helper.rb +26 -5
  124. data/lib/action_view/helpers/date_helper.rb +82 -7
  125. data/lib/action_view/helpers/form_helper.rb +295 -64
  126. data/lib/action_view/helpers/form_options_helper.rb +160 -18
  127. data/lib/action_view/helpers/form_tag_helper.rb +2 -2
  128. data/lib/action_view/helpers/number_helper.rb +31 -18
  129. data/lib/action_view/helpers/prototype_helper.rb +2 -12
  130. data/lib/action_view/helpers/sanitize_helper.rb +0 -10
  131. data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
  132. data/lib/action_view/helpers/tag_helper.rb +3 -4
  133. data/lib/action_view/helpers/text_helper.rb +99 -122
  134. data/lib/action_view/helpers/translation_helper.rb +19 -1
  135. data/lib/action_view/helpers/url_helper.rb +25 -2
  136. data/lib/action_view/inline_template.rb +1 -1
  137. data/lib/action_view/locale/en.yml +19 -1
  138. data/lib/action_view/partials.rb +46 -9
  139. data/lib/action_view/paths.rb +28 -84
  140. data/lib/action_view/reloadable_template.rb +117 -0
  141. data/lib/action_view/renderable.rb +28 -35
  142. data/lib/action_view/renderable_partial.rb +3 -4
  143. data/lib/action_view/template.rb +172 -31
  144. data/lib/action_view/template_error.rb +8 -9
  145. data/lib/action_view/template_handler.rb +1 -1
  146. data/lib/action_view/template_handlers.rb +9 -6
  147. data/lib/action_view/template_handlers/erb.rb +2 -39
  148. data/lib/action_view/template_handlers/rjs.rb +1 -0
  149. data/lib/action_view/test_case.rb +27 -1
  150. data/test/abstract_unit.rb +23 -17
  151. data/test/active_record_unit.rb +5 -4
  152. data/test/activerecord/active_record_store_test.rb +139 -106
  153. data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
  154. data/test/controller/action_pack_assertions_test.rb +25 -23
  155. data/test/controller/addresses_render_test.rb +3 -6
  156. data/test/controller/assert_select_test.rb +83 -70
  157. data/test/controller/base_test.rb +11 -13
  158. data/test/controller/benchmark_test.rb +3 -3
  159. data/test/controller/caching_test.rb +34 -24
  160. data/test/controller/capture_test.rb +3 -6
  161. data/test/controller/content_type_test.rb +3 -6
  162. data/test/controller/cookie_test.rb +31 -66
  163. data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
  164. data/test/controller/dispatcher_test.rb +23 -28
  165. data/test/controller/fake_models.rb +8 -0
  166. data/test/controller/filters_test.rb +6 -2
  167. data/test/controller/flash_test.rb +2 -6
  168. data/test/controller/helper_test.rb +15 -1
  169. data/test/controller/html-scanner/document_test.rb +1 -1
  170. data/test/controller/html-scanner/sanitizer_test.rb +1 -1
  171. data/test/controller/http_basic_authentication_test.rb +88 -0
  172. data/test/controller/http_digest_authentication_test.rb +178 -0
  173. data/test/controller/integration_test.rb +56 -52
  174. data/test/controller/layout_test.rb +46 -44
  175. data/test/controller/middleware_stack_test.rb +90 -0
  176. data/test/controller/mime_responds_test.rb +7 -11
  177. data/test/controller/mime_type_test.rb +9 -0
  178. data/test/controller/polymorphic_routes_test.rb +235 -151
  179. data/test/controller/rack_test.rb +52 -81
  180. data/test/controller/redirect_test.rb +6 -14
  181. data/test/controller/render_test.rb +273 -60
  182. data/test/controller/request/json_params_parsing_test.rb +45 -0
  183. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  184. data/test/controller/request/query_string_parsing_test.rb +120 -0
  185. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  186. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  187. data/test/controller/request_forgery_protection_test.rb +17 -98
  188. data/test/controller/request_test.rb +45 -530
  189. data/test/controller/rescue_test.rb +45 -22
  190. data/test/controller/resources_test.rb +112 -37
  191. data/test/controller/routing_test.rb +1442 -1384
  192. data/test/controller/selector_test.rb +3 -3
  193. data/test/controller/send_file_test.rb +30 -3
  194. data/test/controller/session/cookie_store_test.rb +169 -240
  195. data/test/controller/session/mem_cache_store_test.rb +94 -148
  196. data/test/controller/session/test_session_test.rb +58 -0
  197. data/test/controller/test_test.rb +32 -13
  198. data/test/controller/url_rewriter_test.rb +54 -4
  199. data/test/controller/verification_test.rb +1 -1
  200. data/test/controller/view_paths_test.rb +15 -15
  201. data/test/controller/webservice_test.rb +178 -147
  202. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  203. data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
  204. data/test/fixtures/layouts/default_html.html.erb +1 -0
  205. data/test/fixtures/layouts/xhr.html.erb +2 -0
  206. data/test/fixtures/multipart/empty +10 -0
  207. data/test/fixtures/multipart/hello.txt +1 -0
  208. data/test/fixtures/multipart/none +9 -0
  209. data/test/fixtures/public/500.da.html +1 -0
  210. data/test/fixtures/quiz/questions/_question.html.erb +1 -0
  211. data/test/fixtures/replies.yml +1 -1
  212. data/test/fixtures/test/_one.html.erb +1 -0
  213. data/test/fixtures/test/_two.html.erb +1 -0
  214. data/test/fixtures/test/dont_pick_me +1 -0
  215. data/test/fixtures/test/hello.builder +1 -1
  216. data/test/fixtures/test/hello_world.da.html.erb +1 -0
  217. data/test/fixtures/test/hello_world.erb~ +1 -0
  218. data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
  219. data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
  220. data/test/fixtures/test/malformed/malformed.erb~ +1 -0
  221. data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
  222. data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
  223. data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
  224. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
  225. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
  226. data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
  227. data/test/fixtures/test/utf8.html.erb +2 -0
  228. data/test/template/active_record_helper_i18n_test.rb +31 -33
  229. data/test/template/active_record_helper_test.rb +34 -0
  230. data/test/template/asset_tag_helper_test.rb +52 -14
  231. data/test/template/atom_feed_helper_test.rb +3 -5
  232. data/test/template/benchmark_helper_test.rb +50 -24
  233. data/test/template/compiled_templates_test.rb +177 -33
  234. data/test/template/date_helper_i18n_test.rb +88 -81
  235. data/test/template/date_helper_test.rb +427 -43
  236. data/test/template/form_helper_test.rb +243 -44
  237. data/test/template/form_options_helper_test.rb +631 -565
  238. data/test/template/form_tag_helper_test.rb +9 -2
  239. data/test/template/javascript_helper_test.rb +0 -5
  240. data/test/template/number_helper_i18n_test.rb +60 -48
  241. data/test/template/number_helper_test.rb +1 -0
  242. data/test/template/render_test.rb +117 -35
  243. data/test/template/test_test.rb +4 -6
  244. data/test/template/text_helper_test.rb +129 -50
  245. data/test/template/translation_helper_test.rb +23 -19
  246. data/test/template/url_helper_test.rb +35 -2
  247. data/test/view/test_case_test.rb +8 -0
  248. metadata +197 -23
  249. data/lib/action_controller/assertions.rb +0 -69
  250. data/lib/action_controller/caching/sql_cache.rb +0 -18
  251. data/lib/action_controller/cgi_ext/session.rb +0 -53
  252. data/lib/action_controller/components.rb +0 -169
  253. data/lib/action_controller/rack_process.rb +0 -297
  254. data/lib/action_controller/request_profiler.rb +0 -169
  255. data/lib/action_controller/session/active_record_store.rb +0 -340
  256. data/lib/action_controller/session/drb_server.rb +0 -32
  257. data/lib/action_controller/session/drb_store.rb +0 -35
  258. data/test/controller/cgi_test.rb +0 -269
  259. data/test/controller/components_test.rb +0 -156
  260. data/test/controller/http_authentication_test.rb +0 -54
  261. data/test/controller/integration_upload_test.rb +0 -43
  262. data/test/controller/session_fixation_test.rb +0 -89
  263. data/test/controller/session_management_test.rb +0 -178
  264. data/test/fixtures/test/hello_world.js +0 -1
@@ -1,22 +1,12 @@
1
1
  require 'abstract_unit'
2
- require 'action_controller/integration'
3
- require 'action_controller/routing'
4
-
5
- uses_mocha 'integration' do
6
-
7
- module IntegrationSessionStubbing
8
- def stub_integration_session(session)
9
- session.stubs(:process)
10
- session.stubs(:generic_url_rewriter)
11
- end
12
- end
13
2
 
14
3
  class SessionTest < Test::Unit::TestCase
15
- include IntegrationSessionStubbing
4
+ StubApp = lambda { |env|
5
+ [200, {"Content-Type" => "text/html", "Content-Length" => "13"}, "Hello, World!"]
6
+ }
16
7
 
17
8
  def setup
18
- @session = ActionController::Integration::Session.new
19
- stub_integration_session(@session)
9
+ @session = ActionController::Integration::Session.new(StubApp)
20
10
  end
21
11
 
22
12
  def test_https_bang_works_and_sets_truth_by_default
@@ -38,14 +28,6 @@ class SessionTest < Test::Unit::TestCase
38
28
  assert_raise(RuntimeError) { @session.follow_redirect! }
39
29
  end
40
30
 
41
- def test_follow_redirect_calls_get_and_returns_status
42
- @session.stubs(:redirect?).returns(true)
43
- @session.stubs(:headers).returns({"location" => ["www.google.com"]})
44
- @session.stubs(:status).returns(200)
45
- @session.expects(:get)
46
- assert_equal 200, @session.follow_redirect!
47
- end
48
-
49
31
  def test_request_via_redirect_uses_given_method
50
32
  path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
51
33
  @session.expects(:put).with(path, args, headers)
@@ -209,13 +191,10 @@ class SessionTest < Test::Unit::TestCase
209
191
  end
210
192
 
211
193
  class IntegrationTestTest < Test::Unit::TestCase
212
- include IntegrationSessionStubbing
213
-
214
194
  def setup
215
195
  @test = ::ActionController::IntegrationTest.new(:default_test)
216
196
  @test.class.stubs(:fixture_table_names).returns([])
217
197
  @session = @test.open_session
218
- stub_integration_session(@session)
219
198
  end
220
199
 
221
200
  def test_opens_new_session
@@ -233,15 +212,15 @@ end
233
212
  # Tests that integration tests don't call Controller test methods for processing.
234
213
  # Integration tests have their own setup and teardown.
235
214
  class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
236
- include IntegrationSessionStubbing
237
-
238
215
  def self.fixture_table_names
239
216
  []
240
217
  end
241
218
 
242
219
  def test_integration_methods_called
243
220
  reset!
244
- stub_integration_session(@integration_session)
221
+ @integration_session.stubs(:generic_url_rewriter)
222
+ @integration_session.stubs(:process)
223
+
245
224
  %w( get post head put delete ).each do |verb|
246
225
  assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') }
247
226
  end
@@ -250,8 +229,6 @@ end
250
229
 
251
230
  class IntegrationProcessTest < ActionController::IntegrationTest
252
231
  class IntegrationController < ActionController::Base
253
- session :off
254
-
255
232
  def get
256
233
  respond_to do |format|
257
234
  format.html { render :text => "OK", :status => 200 }
@@ -283,14 +260,11 @@ class IntegrationProcessTest < ActionController::IntegrationTest
283
260
  get '/get'
284
261
  assert_equal 200, status
285
262
  assert_equal "OK", status_message
286
- assert_equal "200 OK", response.headers["Status"]
287
- assert_equal ["200 OK"], headers["status"]
288
263
  assert_response 200
289
264
  assert_response :success
290
265
  assert_response :ok
291
- assert_equal [], response.headers["cookie"]
292
- assert_equal [], headers["cookie"]
293
266
  assert_equal({}, cookies)
267
+ assert_equal "OK", body
294
268
  assert_equal "OK", response.body
295
269
  assert_kind_of HTML::Document, html_document
296
270
  assert_equal 1, request_count
@@ -302,14 +276,11 @@ class IntegrationProcessTest < ActionController::IntegrationTest
302
276
  post '/post'
303
277
  assert_equal 201, status
304
278
  assert_equal "Created", status_message
305
- assert_equal "201 Created", response.headers["Status"]
306
- assert_equal ["201 Created"], headers["status"]
307
279
  assert_response 201
308
280
  assert_response :success
309
281
  assert_response :created
310
- assert_equal [], response.headers["cookie"]
311
- assert_equal [], headers["cookie"]
312
282
  assert_equal({}, cookies)
283
+ assert_equal "Created", body
313
284
  assert_equal "Created", response.body
314
285
  assert_kind_of HTML::Document, html_document
315
286
  assert_equal 1, request_count
@@ -323,17 +294,9 @@ class IntegrationProcessTest < ActionController::IntegrationTest
323
294
  get '/cookie_monster'
324
295
  assert_equal 410, status
325
296
  assert_equal "Gone", status_message
326
- assert_equal "410 Gone", response.headers["Status"]
327
- assert_equal ["410 Gone"], headers["status"]
328
297
  assert_response 410
329
298
  assert_response :gone
330
- assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], response.headers["Set-Cookie"]
331
- assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers['set-cookie']
332
- assert_equal [
333
- CGI::Cookie::new("name" => "cookie_1", "value" => ""),
334
- CGI::Cookie::new("name" => "cookie_3", "value" => "chocolate")
335
- ], response.headers["cookie"]
336
- assert_equal [], headers["cookie"]
299
+ assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
337
300
  assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
338
301
  assert_equal "Gone", response.body
339
302
  end
@@ -344,14 +307,16 @@ class IntegrationProcessTest < ActionController::IntegrationTest
344
307
  get '/redirect'
345
308
  assert_equal 302, status
346
309
  assert_equal "Found", status_message
347
- assert_equal "302 Found", response.headers["Status"]
348
- assert_equal ["302 Found"], headers["status"]
349
310
  assert_response 302
350
311
  assert_response :redirect
351
312
  assert_response :found
352
313
  assert_equal "<html><body>You are being <a href=\"http://www.example.com/get\">redirected</a>.</body></html>", response.body
353
314
  assert_kind_of HTML::Document, html_document
354
315
  assert_equal 1, request_count
316
+
317
+ follow_redirect!
318
+ assert_response :success
319
+ assert_equal "/get", path
355
320
  end
356
321
  end
357
322
 
@@ -360,8 +325,6 @@ class IntegrationProcessTest < ActionController::IntegrationTest
360
325
  xhr :get, '/get'
361
326
  assert_equal 200, status
362
327
  assert_equal "OK", status_message
363
- assert_equal "200 OK", response.headers["Status"]
364
- assert_equal ["200 OK"], headers["status"]
365
328
  assert_response 200
366
329
  assert_response :success
367
330
  assert_response :ok
@@ -374,7 +337,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
374
337
  get '/get_with_params?foo=bar'
375
338
  assert_equal '/get_with_params?foo=bar', request.env["REQUEST_URI"]
376
339
  assert_equal '/get_with_params?foo=bar', request.request_uri
377
- assert_equal nil, request.env["QUERY_STRING"]
340
+ assert_equal "", request.env["QUERY_STRING"]
378
341
  assert_equal 'foo=bar', request.query_string
379
342
  assert_equal 'bar', request.parameters['foo']
380
343
 
@@ -397,6 +360,18 @@ class IntegrationProcessTest < ActionController::IntegrationTest
397
360
  end
398
361
  end
399
362
 
363
+ def test_head
364
+ with_test_route_set do
365
+ head '/get'
366
+ assert_equal 200, status
367
+ assert_equal "", body
368
+
369
+ head '/post'
370
+ assert_equal 201, status
371
+ assert_equal "", body
372
+ end
373
+ end
374
+
400
375
  private
401
376
  def with_test_route_set
402
377
  with_routing do |set|
@@ -410,4 +385,33 @@ class IntegrationProcessTest < ActionController::IntegrationTest
410
385
  end
411
386
  end
412
387
 
388
+ class MetalTest < ActionController::IntegrationTest
389
+ class Poller
390
+ def self.call(env)
391
+ if env["PATH_INFO"] =~ /^\/success/
392
+ [200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, "Hello World!"]
393
+ else
394
+ [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, '']
395
+ end
396
+ end
397
+ end
398
+
399
+ def setup
400
+ @integration_session = ActionController::Integration::Session.new(Poller)
401
+ end
402
+
403
+ def test_successful_get
404
+ get "/success"
405
+ assert_response 200
406
+ assert_response :success
407
+ assert_response :ok
408
+ assert_equal "Hello World!", response.body
409
+ end
410
+
411
+ def test_failed_get
412
+ get "/failure"
413
+ assert_response 404
414
+ assert_response :not_found
415
+ assert_equal '', response.body
416
+ end
413
417
  end
@@ -3,6 +3,10 @@ require 'abstract_unit'
3
3
  # The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
4
4
  # method has access to the view_paths array when looking for a layout to automatically assign.
5
5
  old_load_paths = ActionController::Base.view_paths
6
+
7
+ ActionView::Template::register_template_handler :mab,
8
+ lambda { |template| template.source.inspect }
9
+
6
10
  ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
7
11
 
8
12
  class LayoutTest < ActionController::Base
@@ -31,14 +35,8 @@ end
31
35
  class MultipleExtensions < LayoutTest
32
36
  end
33
37
 
34
- ActionView::Template::register_template_handler :mab,
35
- lambda { |template| template.source.inspect }
36
-
37
- class LayoutAutoDiscoveryTest < Test::Unit::TestCase
38
+ class LayoutAutoDiscoveryTest < ActionController::TestCase
38
39
  def setup
39
- @request = ActionController::TestRequest.new
40
- @response = ActionController::TestResponse.new
41
-
42
40
  @request.host = "www.nextangle.com"
43
41
  end
44
42
 
@@ -55,10 +53,9 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
55
53
  end
56
54
 
57
55
  def test_third_party_template_library_auto_discovers_layout
58
- ThirdPartyTemplateLibraryController.view_paths.reload!
59
56
  @controller = ThirdPartyTemplateLibraryController.new
60
57
  get :hello
61
- assert_equal 'layouts/third_party_template_library', @controller.active_layout
58
+ assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout.to_s
62
59
  assert_equal 'layouts/third_party_template_library', @response.layout
63
60
  assert_response :success
64
61
  assert_equal 'Mab', @response.body
@@ -67,14 +64,14 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
67
64
  def test_namespaced_controllers_auto_detect_layouts
68
65
  @controller = ControllerNameSpace::NestedController.new
69
66
  get :hello
70
- assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
67
+ assert_equal 'layouts/controller_name_space/nested', @controller.active_layout.to_s
71
68
  assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
72
69
  end
73
70
 
74
71
  def test_namespaced_controllers_auto_detect_layouts
75
72
  @controller = MultipleExtensions.new
76
73
  get :hello
77
- assert_equal 'layouts/multiple_extensions', @controller.active_layout
74
+ assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout.to_s
78
75
  assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
79
76
  end
80
77
  end
@@ -82,10 +79,21 @@ end
82
79
  class DefaultLayoutController < LayoutTest
83
80
  end
84
81
 
82
+ class AbsolutePathLayoutController < LayoutTest
83
+ layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
84
+ end
85
+
85
86
  class HasOwnLayoutController < LayoutTest
86
87
  layout 'item'
87
88
  end
88
89
 
90
+ class PrependsViewPathController < LayoutTest
91
+ def hello
92
+ prepend_view_path File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/'
93
+ render :layout => 'alt'
94
+ end
95
+ end
96
+
89
97
  class SetsLayoutInRenderController < LayoutTest
90
98
  def hello
91
99
  render :layout => 'third_party_template_library'
@@ -98,12 +106,7 @@ class RendersNoLayoutController < LayoutTest
98
106
  end
99
107
  end
100
108
 
101
- class LayoutSetInResponseTest < Test::Unit::TestCase
102
- def setup
103
- @request = ActionController::TestRequest.new
104
- @response = ActionController::TestResponse.new
105
- end
106
-
109
+ class LayoutSetInResponseTest < ActionController::TestCase
107
110
  def test_layout_set_when_using_default_layout
108
111
  @controller = DefaultLayoutController.new
109
112
  get :hello
@@ -138,6 +141,18 @@ class LayoutSetInResponseTest < Test::Unit::TestCase
138
141
  ensure
139
142
  ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
140
143
  end
144
+
145
+ def test_layout_is_picked_from_the_controller_instances_view_path
146
+ @controller = PrependsViewPathController.new
147
+ get :hello
148
+ assert_equal 'layouts/alt', @response.layout
149
+ end
150
+
151
+ def test_absolute_pathed_layout
152
+ @controller = AbsolutePathLayoutController.new
153
+ get :hello
154
+ assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
155
+ end
141
156
  end
142
157
 
143
158
  class RenderWithTemplateOptionController < LayoutTest
@@ -150,17 +165,11 @@ class SetsNonExistentLayoutFile < LayoutTest
150
165
  layout "nofile.rhtml"
151
166
  end
152
167
 
153
- class LayoutExceptionRaised < Test::Unit::TestCase
154
- def setup
155
- @request = ActionController::TestRequest.new
156
- @response = ActionController::TestResponse.new
157
- end
158
-
168
+ class LayoutExceptionRaised < ActionController::TestCase
159
169
  def test_exception_raised_when_layout_file_not_found
160
170
  @controller = SetsNonExistentLayoutFile.new
161
171
  get :hello
162
- @response.template.class.module_eval { attr_accessor :exception }
163
- assert_equal ActionView::MissingTemplate, @response.template.exception.class
172
+ assert_kind_of ActionView::MissingTemplate, @response.template.instance_eval { @exception }
164
173
  end
165
174
  end
166
175
 
@@ -170,12 +179,7 @@ class LayoutStatusIsRendered < LayoutTest
170
179
  end
171
180
  end
172
181
 
173
- class LayoutStatusIsRenderedTest < Test::Unit::TestCase
174
- def setup
175
- @request = ActionController::TestRequest.new
176
- @response = ActionController::TestResponse.new
177
- end
178
-
182
+ class LayoutStatusIsRenderedTest < ActionController::TestCase
179
183
  def test_layout_status_is_rendered
180
184
  @controller = LayoutStatusIsRendered.new
181
185
  get :hello
@@ -183,20 +187,18 @@ class LayoutStatusIsRenderedTest < Test::Unit::TestCase
183
187
  end
184
188
  end
185
189
 
186
- class LayoutSymlinkedTest < LayoutTest
187
- layout "symlinked/symlinked_layout"
188
- end
189
-
190
- class LayoutSymlinkedIsRenderedTest < Test::Unit::TestCase
191
- def setup
192
- @request = ActionController::TestRequest.new
193
- @response = ActionController::TestResponse.new
190
+ unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/
191
+ class LayoutSymlinkedTest < LayoutTest
192
+ layout "symlinked/symlinked_layout"
194
193
  end
195
194
 
196
- def test_symlinked_layout_is_rendered
197
- @controller = LayoutSymlinkedTest.new
198
- get :hello
199
- assert_response 200
200
- assert_equal "layouts/symlinked/symlinked_layout", @response.layout
195
+ class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
196
+ def test_symlinked_layout_is_rendered
197
+ @controller = LayoutSymlinkedTest.new
198
+ get :hello
199
+ assert_response 200
200
+ assert_equal "layouts/symlinked/symlinked_layout", @response.layout
201
+ end
201
202
  end
202
203
  end
204
+
@@ -0,0 +1,90 @@
1
+ require 'abstract_unit'
2
+
3
+ class MiddlewareStackTest < ActiveSupport::TestCase
4
+ class FooMiddleware; end
5
+ class BarMiddleware; end
6
+ class BazMiddleware; end
7
+
8
+ def setup
9
+ @stack = ActionController::MiddlewareStack.new
10
+ @stack.use FooMiddleware
11
+ @stack.use BarMiddleware
12
+ end
13
+
14
+ test "use should push middleware as class onto the stack" do
15
+ assert_difference "@stack.size" do
16
+ @stack.use BazMiddleware
17
+ end
18
+ assert_equal BazMiddleware, @stack.last.klass
19
+ end
20
+
21
+ test "use should push middleware as a string onto the stack" do
22
+ assert_difference "@stack.size" do
23
+ @stack.use "MiddlewareStackTest::BazMiddleware"
24
+ end
25
+ assert_equal BazMiddleware, @stack.last.klass
26
+ end
27
+
28
+ test "use should push middleware as a symbol onto the stack" do
29
+ assert_difference "@stack.size" do
30
+ @stack.use :"MiddlewareStackTest::BazMiddleware"
31
+ end
32
+ assert_equal BazMiddleware, @stack.last.klass
33
+ end
34
+
35
+ test "use should push middleware class with arguments onto the stack" do
36
+ assert_difference "@stack.size" do
37
+ @stack.use BazMiddleware, true, :foo => "bar"
38
+ end
39
+ assert_equal BazMiddleware, @stack.last.klass
40
+ assert_equal([true, {:foo => "bar"}], @stack.last.args)
41
+ end
42
+
43
+ test "insert inserts middleware at the integer index" do
44
+ @stack.insert(1, BazMiddleware)
45
+ assert_equal BazMiddleware, @stack[1].klass
46
+ end
47
+
48
+ test "insert_after inserts middleware after the integer index" do
49
+ @stack.insert_after(1, BazMiddleware)
50
+ assert_equal BazMiddleware, @stack[2].klass
51
+ end
52
+
53
+ test "insert_before inserts middleware before another middleware class" do
54
+ @stack.insert_before(BarMiddleware, BazMiddleware)
55
+ assert_equal BazMiddleware, @stack[1].klass
56
+ end
57
+
58
+ test "insert_after inserts middleware after another middleware class" do
59
+ @stack.insert_after(BarMiddleware, BazMiddleware)
60
+ assert_equal BazMiddleware, @stack[2].klass
61
+ end
62
+
63
+ test "swaps one middleware out for another" do
64
+ assert_equal FooMiddleware, @stack[0].klass
65
+ @stack.swap(FooMiddleware, BazMiddleware)
66
+ assert_equal BazMiddleware, @stack[0].klass
67
+ end
68
+
69
+ test "active returns all only enabled middleware" do
70
+ assert_no_difference "@stack.active.size" do
71
+ assert_difference "@stack.size" do
72
+ @stack.use BazMiddleware, :if => lambda { false }
73
+ end
74
+ end
75
+ end
76
+
77
+ test "lazy evaluates middleware class" do
78
+ assert_difference "@stack.size" do
79
+ @stack.use lambda { BazMiddleware }
80
+ end
81
+ assert_equal BazMiddleware, @stack.last.klass
82
+ end
83
+
84
+ test "lazy evaluates middleware arguments" do
85
+ assert_difference "@stack.size" do
86
+ @stack.use BazMiddleware, lambda { :foo }
87
+ end
88
+ assert_equal [:foo], @stack.last.send(:build_args)
89
+ end
90
+ end