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
@@ -47,19 +47,13 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base
47
47
  end
48
48
 
49
49
  class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
50
+ tests RenderPartialWithRecordIdentificationController
50
51
  fixtures :developers, :projects, :developers_projects, :topics, :replies, :companies, :mascots
51
52
 
52
- def setup
53
- @controller = RenderPartialWithRecordIdentificationController.new
54
- @request = ActionController::TestRequest.new
55
- @response = ActionController::TestResponse.new
56
- super
57
- end
58
-
59
53
  def test_rendering_partial_with_has_many_and_belongs_to_association
60
54
  get :render_with_has_many_and_belongs_to_association
61
55
  assert_template 'projects/_project'
62
- assert_equal 'Active RecordActive Controller', @response.body
56
+ assert_equal assigns(:developer).projects.map(&:name).join, @response.body
63
57
  end
64
58
 
65
59
  def test_rendering_partial_with_has_many_association
@@ -88,7 +82,7 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
88
82
 
89
83
  def test_render_with_record_collection_and_spacer_template
90
84
  get :render_with_record_collection_and_spacer_template
91
- assert_equal 'Active Recordonly partialActive Controller', @response.body
85
+ assert_equal assigns(:developer).projects.map(&:name).join('only partial'), @response.body
92
86
  end
93
87
 
94
88
  def test_rendering_partial_with_has_one_association
@@ -162,12 +156,7 @@ module Fun
162
156
  end
163
157
 
164
158
  class RenderPartialWithRecordIdentificationAndNestedControllersTest < ActiveRecordTestCase
165
- def setup
166
- @controller = Fun::NestedController.new
167
- @request = ActionController::TestRequest.new
168
- @response = ActionController::TestResponse.new
169
- super
170
- end
159
+ tests Fun::NestedController
171
160
 
172
161
  def test_render_with_record_in_nested_controller
173
162
  get :render_with_record_in_nested_controller
@@ -183,12 +172,7 @@ class RenderPartialWithRecordIdentificationAndNestedControllersTest < ActiveReco
183
172
  end
184
173
 
185
174
  class RenderPartialWithRecordIdentificationAndNestedDeeperControllersTest < ActiveRecordTestCase
186
- def setup
187
- @controller = Fun::Serious::NestedDeeperController.new
188
- @request = ActionController::TestRequest.new
189
- @response = ActionController::TestResponse.new
190
- super
191
- end
175
+ tests Fun::Serious::NestedDeeperController
192
176
 
193
177
  def test_render_with_record_in_deeper_nested_controller
194
178
  get :render_with_record_in_deeper_nested_controller
@@ -165,13 +165,11 @@ module Admin
165
165
  end
166
166
 
167
167
  # a test case to exercise the new capabilities TestRequest & TestResponse
168
- class ActionPackAssertionsControllerTest < Test::Unit::TestCase
168
+ class ActionPackAssertionsControllerTest < ActionController::TestCase
169
169
  # let's get this party started
170
170
  def setup
171
171
  ActionController::Routing::Routes.reload
172
172
  ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
173
- @controller = ActionPackAssertionsController.new
174
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
175
173
  end
176
174
 
177
175
  def teardown
@@ -235,13 +233,13 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
235
233
  map.connect ':controller/:action/:id'
236
234
  end
237
235
  process :redirect_to_named_route
238
- assert_raise(Test::Unit::AssertionFailedError) do
236
+ assert_raise(ActiveSupport::TestCase::Assertion) do
239
237
  assert_redirected_to 'http://test.host/route_two'
240
238
  end
241
- assert_raise(Test::Unit::AssertionFailedError) do
239
+ assert_raise(ActiveSupport::TestCase::Assertion) do
242
240
  assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
243
241
  end
244
- assert_raise(Test::Unit::AssertionFailedError) do
242
+ assert_raise(ActiveSupport::TestCase::Assertion) do
245
243
  assert_redirected_to route_two_url
246
244
  end
247
245
  end
@@ -328,11 +326,11 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
328
326
  # check if we were rendered by a file-based template?
329
327
  def test_rendered_action
330
328
  process :nothing
331
- assert_nil @response.rendered_template
329
+ assert_nil @response.rendered[:template]
332
330
 
333
331
  process :hello_world
334
- assert @response.rendered_template
335
- assert 'hello_world', @response.rendered_template.to_s
332
+ assert @response.rendered[:template]
333
+ assert 'hello_world', @response.rendered[:template].to_s
336
334
  end
337
335
 
338
336
  # check the redirection location
@@ -368,6 +366,12 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
368
366
  assert @response.missing?
369
367
  end
370
368
 
369
+ # check client errors
370
+ def test_client_error_response_code
371
+ process :response404
372
+ assert @response.client_error?
373
+ end
374
+
371
375
  # check to see if our redirection matches a pattern
372
376
  def test_redirect_url_match
373
377
  process :redirect_external
@@ -410,7 +414,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
410
414
 
411
415
  def test_assert_redirection_fails_with_incorrect_controller
412
416
  process :redirect_to_controller
413
- assert_raise(Test::Unit::AssertionFailedError) do
417
+ assert_raise(ActiveSupport::TestCase::Assertion) do
414
418
  assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me"
415
419
  end
416
420
  end
@@ -457,16 +461,16 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
457
461
 
458
462
  def test_assert_valid
459
463
  get :get_valid_record
460
- assert_valid assigns('record')
464
+ assert_deprecated { assert_valid assigns('record') }
461
465
  end
462
466
 
463
467
  def test_assert_valid_failing
464
468
  get :get_invalid_record
465
469
 
466
470
  begin
467
- assert_valid assigns('record')
471
+ assert_deprecated { assert_valid assigns('record') }
468
472
  assert false
469
- rescue Test::Unit::AssertionFailedError => e
473
+ rescue ActiveSupport::TestCase::Assertion => e
470
474
  end
471
475
  end
472
476
 
@@ -475,7 +479,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
475
479
  get :index
476
480
  assert_response :success
477
481
  flunk 'Expected non-success response'
478
- rescue Test::Unit::AssertionFailedError => e
482
+ rescue ActiveSupport::TestCase::Assertion => e
479
483
  assert e.message.include?('FAIL')
480
484
  end
481
485
 
@@ -484,31 +488,29 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
484
488
  get :show
485
489
  assert_response :success
486
490
  flunk 'Expected non-success response'
487
- rescue Test::Unit::AssertionFailedError
491
+ rescue ActiveSupport::TestCase::Assertion
492
+ # success
488
493
  rescue
489
494
  flunk "assert_response failed to handle failure response with missing, but optional, exception."
490
495
  end
491
496
  end
492
497
 
493
- class ActionPackHeaderTest < Test::Unit::TestCase
494
- def setup
495
- @controller = ActionPackAssertionsController.new
496
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
497
- end
498
+ class ActionPackHeaderTest < ActionController::TestCase
499
+ tests ActionPackAssertionsController
498
500
 
499
501
  def test_rendering_xml_sets_content_type
500
502
  process :hello_xml_world
501
- assert_equal('application/xml; charset=utf-8', @response.headers['type'])
503
+ assert_equal('application/xml; charset=utf-8', @response.headers['Content-Type'])
502
504
  end
503
505
 
504
506
  def test_rendering_xml_respects_content_type
505
507
  @response.headers['type'] = 'application/pdf'
506
508
  process :hello_xml_world
507
- assert_equal('application/pdf; charset=utf-8', @response.headers['type'])
509
+ assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type'])
508
510
  end
509
511
 
510
512
  def test_render_text_with_custom_content_type
511
513
  get :render_text_with_custom_content_type
512
- assert_equal 'application/rss+xml; charset=utf-8', @response.headers['type']
514
+ assert_equal 'application/rss+xml; charset=utf-8', @response.headers['Content-Type']
513
515
  end
514
516
  end
@@ -19,17 +19,14 @@ class AddressesTestController < ActionController::Base
19
19
  def self.controller_path; "addresses"; end
20
20
  end
21
21
 
22
- class AddressesTest < Test::Unit::TestCase
23
- def setup
24
- @controller = AddressesTestController.new
22
+ class AddressesTest < ActionController::TestCase
23
+ tests AddressesTestController
25
24
 
25
+ def setup
26
26
  # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
27
27
  # a more accurate simulation of what happens in "real life".
28
28
  @controller.logger = Logger.new(nil)
29
29
 
30
- @request = ActionController::TestRequest.new
31
- @response = ActionController::TestResponse.new
32
-
33
30
  @request.host = "www.nextangle.com"
34
31
  end
35
32
 
@@ -9,9 +9,10 @@ require 'controller/fake_controllers'
9
9
 
10
10
  unless defined?(ActionMailer)
11
11
  begin
12
- $:.unshift(File.dirname(__FILE__) + "/../../../actionmailer/lib")
12
+ $:.unshift("#{File.dirname(__FILE__)}/../../../actionmailer/lib")
13
13
  require 'action_mailer'
14
- rescue LoadError
14
+ rescue LoadError => e
15
+ raise unless e.message =~ /action_mailer/
15
16
  require 'rubygems'
16
17
  gem 'actionmailer'
17
18
  end
@@ -19,7 +20,18 @@ end
19
20
 
20
21
  ActionMailer::Base.template_root = FIXTURE_LOAD_PATH
21
22
 
22
- class AssertSelectTest < Test::Unit::TestCase
23
+ class AssertSelectTest < ActionController::TestCase
24
+ Assertion = ActiveSupport::TestCase::Assertion
25
+
26
+ class AssertSelectMailer < ActionMailer::Base
27
+ def test(html)
28
+ recipients "test <test@test.host>"
29
+ from "test@test.host"
30
+ subject "Test e-mail"
31
+ part :content_type=>"text/html", :body=>html
32
+ end
33
+ end
34
+
23
35
  class AssertSelectController < ActionController::Base
24
36
  def response_with=(content)
25
37
  @content = content
@@ -51,21 +63,9 @@ class AssertSelectTest < Test::Unit::TestCase
51
63
  end
52
64
  end
53
65
 
54
- class AssertSelectMailer < ActionMailer::Base
55
- def test(html)
56
- recipients "test <test@test.host>"
57
- from "test@test.host"
58
- subject "Test e-mail"
59
- part :content_type=>"text/html", :body=>html
60
- end
61
- end
62
-
63
- AssertionFailedError = Test::Unit::AssertionFailedError
66
+ tests AssertSelectController
64
67
 
65
68
  def setup
66
- @controller = AssertSelectController.new
67
- @request = ActionController::TestRequest.new
68
- @response = ActionController::TestResponse.new
69
69
  ActionMailer::Base.delivery_method = :test
70
70
  ActionMailer::Base.perform_deliveries = true
71
71
  ActionMailer::Base.deliveries = []
@@ -76,7 +76,7 @@ class AssertSelectTest < Test::Unit::TestCase
76
76
  end
77
77
 
78
78
  def assert_failure(message, &block)
79
- e = assert_raises(AssertionFailedError, &block)
79
+ e = assert_raise(Assertion, &block)
80
80
  assert_match(message, e.message) if Regexp === message
81
81
  assert_equal(message, e.message) if String === message
82
82
  end
@@ -94,43 +94,43 @@ class AssertSelectTest < Test::Unit::TestCase
94
94
 
95
95
  def test_equality_true_false
96
96
  render_html %Q{<div id="1"></div><div id="2"></div>}
97
- assert_nothing_raised { assert_select "div" }
98
- assert_raises(AssertionFailedError) { assert_select "p" }
99
- assert_nothing_raised { assert_select "div", true }
100
- assert_raises(AssertionFailedError) { assert_select "p", true }
101
- assert_raises(AssertionFailedError) { assert_select "div", false }
102
- assert_nothing_raised { assert_select "p", false }
97
+ assert_nothing_raised { assert_select "div" }
98
+ assert_raise(Assertion) { assert_select "p" }
99
+ assert_nothing_raised { assert_select "div", true }
100
+ assert_raise(Assertion) { assert_select "p", true }
101
+ assert_raise(Assertion) { assert_select "div", false }
102
+ assert_nothing_raised { assert_select "p", false }
103
103
  end
104
104
 
105
105
  def test_equality_string_and_regexp
106
106
  render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
107
- assert_nothing_raised { assert_select "div", "foo" }
108
- assert_raises(AssertionFailedError) { assert_select "div", "bar" }
109
- assert_nothing_raised { assert_select "div", :text=>"foo" }
110
- assert_raises(AssertionFailedError) { assert_select "div", :text=>"bar" }
111
- assert_nothing_raised { assert_select "div", /(foo|bar)/ }
112
- assert_raises(AssertionFailedError) { assert_select "div", /foobar/ }
113
- assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
114
- assert_raises(AssertionFailedError) { assert_select "div", :text=>/foobar/ }
115
- assert_raises(AssertionFailedError) { assert_select "p", :text=>/foobar/ }
107
+ assert_nothing_raised { assert_select "div", "foo" }
108
+ assert_raise(Assertion) { assert_select "div", "bar" }
109
+ assert_nothing_raised { assert_select "div", :text=>"foo" }
110
+ assert_raise(Assertion) { assert_select "div", :text=>"bar" }
111
+ assert_nothing_raised { assert_select "div", /(foo|bar)/ }
112
+ assert_raise(Assertion) { assert_select "div", /foobar/ }
113
+ assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
114
+ assert_raise(Assertion) { assert_select "div", :text=>/foobar/ }
115
+ assert_raise(Assertion) { assert_select "p", :text=>/foobar/ }
116
116
  end
117
117
 
118
118
  def test_equality_of_html
119
119
  render_html %Q{<p>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</p>}
120
120
  text = "\"This is not a big problem,\" he said."
121
121
  html = "<em>\"This is <strong>not</strong> a big problem,\"</em> he said."
122
- assert_nothing_raised { assert_select "p", text }
123
- assert_raises(AssertionFailedError) { assert_select "p", html }
124
- assert_nothing_raised { assert_select "p", :html=>html }
125
- assert_raises(AssertionFailedError) { assert_select "p", :html=>text }
122
+ assert_nothing_raised { assert_select "p", text }
123
+ assert_raise(Assertion) { assert_select "p", html }
124
+ assert_nothing_raised { assert_select "p", :html=>html }
125
+ assert_raise(Assertion) { assert_select "p", :html=>text }
126
126
  # No stripping for pre.
127
127
  render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>}
128
128
  text = "\n\"This is not a big problem,\" he said.\n"
129
129
  html = "\n<em>\"This is <strong>not</strong> a big problem,\"</em> he said.\n"
130
- assert_nothing_raised { assert_select "pre", text }
131
- assert_raises(AssertionFailedError) { assert_select "pre", html }
132
- assert_nothing_raised { assert_select "pre", :html=>html }
133
- assert_raises(AssertionFailedError) { assert_select "pre", :html=>text }
130
+ assert_nothing_raised { assert_select "pre", text }
131
+ assert_raise(Assertion) { assert_select "pre", html }
132
+ assert_nothing_raised { assert_select "pre", :html=>html }
133
+ assert_raise(Assertion) { assert_select "pre", :html=>text }
134
134
  end
135
135
 
136
136
  def test_counts
@@ -206,16 +206,16 @@ class AssertSelectTest < Test::Unit::TestCase
206
206
  def test_assert_select_text_match
207
207
  render_html %Q{<div id="1"><span>foo</span></div><div id="2"><span>bar</span></div>}
208
208
  assert_select "div" do
209
- assert_nothing_raised { assert_select "div", "foo" }
210
- assert_nothing_raised { assert_select "div", "bar" }
211
- assert_nothing_raised { assert_select "div", /\w*/ }
212
- assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
213
- assert_raises(AssertionFailedError) { assert_select "div", :text=>"foo", :count=>2 }
214
- assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
215
- assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
216
- assert_nothing_raised { assert_select "div", :html=>/\w*/ }
217
- assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
218
- assert_raises(AssertionFailedError) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
209
+ assert_nothing_raised { assert_select "div", "foo" }
210
+ assert_nothing_raised { assert_select "div", "bar" }
211
+ assert_nothing_raised { assert_select "div", /\w*/ }
212
+ assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
213
+ assert_raise(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
214
+ assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
215
+ assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
216
+ assert_nothing_raised { assert_select "div", :html=>/\w*/ }
217
+ assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
218
+ assert_raise(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
219
219
  end
220
220
  end
221
221
 
@@ -248,6 +248,19 @@ class AssertSelectTest < Test::Unit::TestCase
248
248
  end
249
249
  end
250
250
 
251
+ def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_arguments
252
+ render_rjs do |page|
253
+ page.insert_html :top, "test1", "<div id=\"1\">foo</div>"
254
+ page.insert_html :bottom, "test2", "<div id=\"2\">foo</div>"
255
+ end
256
+ assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"}
257
+ end
258
+
259
+ def test_elect_with_xml_namespace_attributes
260
+ render_html %Q{<link xlink:href="http://nowhere.com"></link>}
261
+ assert_nothing_raised { assert_select "link[xlink:href=http://nowhere.com]" }
262
+ end
263
+
251
264
  #
252
265
  # Test css_select.
253
266
  #
@@ -323,7 +336,7 @@ class AssertSelectTest < Test::Unit::TestCase
323
336
  # Test that we fail if there is nothing to pick.
324
337
  def test_assert_select_rjs_fails_if_nothing_to_pick
325
338
  render_rjs { }
326
- assert_raises(AssertionFailedError) { assert_select_rjs }
339
+ assert_raise(Assertion) { assert_select_rjs }
327
340
  end
328
341
 
329
342
  def test_assert_select_rjs_with_unicode
@@ -338,10 +351,10 @@ class AssertSelectTest < Test::Unit::TestCase
338
351
  if str.respond_to?(:force_encoding)
339
352
  str.force_encoding(Encoding::UTF_8)
340
353
  assert_select str, /\343\203\201..\343\203\210/u
341
- assert_raises(AssertionFailedError) { assert_select str, /\343\203\201.\343\203\210/u }
354
+ assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
342
355
  else
343
356
  assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
344
- assert_raises(AssertionFailedError) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
357
+ assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
345
358
  end
346
359
  end
347
360
  end
@@ -365,7 +378,7 @@ class AssertSelectTest < Test::Unit::TestCase
365
378
  assert_select "div", 1
366
379
  assert_select "#3"
367
380
  end
368
- assert_raises(AssertionFailedError) { assert_select_rjs "test4" }
381
+ assert_raise(Assertion) { assert_select_rjs "test4" }
369
382
  end
370
383
 
371
384
  def test_assert_select_rjs_for_replace
@@ -383,7 +396,7 @@ class AssertSelectTest < Test::Unit::TestCase
383
396
  assert_select "div", 1
384
397
  assert_select "#1"
385
398
  end
386
- assert_raises(AssertionFailedError) { assert_select_rjs :replace, "test2" }
399
+ assert_raise(Assertion) { assert_select_rjs :replace, "test2" }
387
400
  # Replace HTML.
388
401
  assert_select_rjs :replace_html do
389
402
  assert_select "div", 1
@@ -393,7 +406,7 @@ class AssertSelectTest < Test::Unit::TestCase
393
406
  assert_select "div", 1
394
407
  assert_select "#2"
395
408
  end
396
- assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" }
409
+ assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
397
410
  end
398
411
 
399
412
  def test_assert_select_rjs_for_chained_replace
@@ -411,7 +424,7 @@ class AssertSelectTest < Test::Unit::TestCase
411
424
  assert_select "div", 1
412
425
  assert_select "#1"
413
426
  end
414
- assert_raises(AssertionFailedError) { assert_select_rjs :chained_replace, "test2" }
427
+ assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" }
415
428
  # Replace HTML.
416
429
  assert_select_rjs :chained_replace_html do
417
430
  assert_select "div", 1
@@ -421,7 +434,7 @@ class AssertSelectTest < Test::Unit::TestCase
421
434
  assert_select "div", 1
422
435
  assert_select "#2"
423
436
  end
424
- assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" }
437
+ assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
425
438
  end
426
439
 
427
440
  # Simple remove
@@ -440,8 +453,8 @@ class AssertSelectTest < Test::Unit::TestCase
440
453
 
441
454
  assert_select_rjs :remove, "test1"
442
455
 
443
- rescue Test::Unit::AssertionFailedError
444
- assert_equal "No RJS statement that removes 'test1' was rendered.", $!.message
456
+ rescue Assertion
457
+ assert_equal "No RJS statement that removes 'test1' was rendered.", $!.message
445
458
  end
446
459
 
447
460
  def test_assert_select_rjs_for_remove_ignores_block
@@ -472,8 +485,8 @@ class AssertSelectTest < Test::Unit::TestCase
472
485
 
473
486
  assert_select_rjs :show, "test1"
474
487
 
475
- rescue Test::Unit::AssertionFailedError
476
- assert_equal "No RJS statement that shows 'test1' was rendered.", $!.message
488
+ rescue Assertion
489
+ assert_equal "No RJS statement that shows 'test1' was rendered.", $!.message
477
490
  end
478
491
 
479
492
  def test_assert_select_rjs_for_show_ignores_block
@@ -504,8 +517,8 @@ class AssertSelectTest < Test::Unit::TestCase
504
517
 
505
518
  assert_select_rjs :hide, "test1"
506
519
 
507
- rescue Test::Unit::AssertionFailedError
508
- assert_equal "No RJS statement that hides 'test1' was rendered.", $!.message
520
+ rescue Assertion
521
+ assert_equal "No RJS statement that hides 'test1' was rendered.", $!.message
509
522
  end
510
523
 
511
524
  def test_assert_select_rjs_for_hide_ignores_block
@@ -536,8 +549,8 @@ class AssertSelectTest < Test::Unit::TestCase
536
549
 
537
550
  assert_select_rjs :toggle, "test1"
538
551
 
539
- rescue Test::Unit::AssertionFailedError
540
- assert_equal "No RJS statement that toggles 'test1' was rendered.", $!.message
552
+ rescue Assertion
553
+ assert_equal "No RJS statement that toggles 'test1' was rendered.", $!.message
541
554
  end
542
555
 
543
556
  def test_assert_select_rjs_for_toggle_ignores_block
@@ -567,7 +580,7 @@ class AssertSelectTest < Test::Unit::TestCase
567
580
  assert_select "div", 1
568
581
  assert_select "#3"
569
582
  end
570
- assert_raises(AssertionFailedError) { assert_select_rjs :insert_html, "test1" }
583
+ assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" }
571
584
  end
572
585
 
573
586
  # Positioned insert.
@@ -600,8 +613,8 @@ class AssertSelectTest < Test::Unit::TestCase
600
613
  end
601
614
 
602
615
  def test_assert_select_rjs_raise_errors
603
- assert_raises(ArgumentError) { assert_select_rjs(:destroy) }
604
- assert_raises(ArgumentError) { assert_select_rjs(:insert, :left) }
616
+ assert_raise(ArgumentError) { assert_select_rjs(:destroy) }
617
+ assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) }
605
618
  end
606
619
 
607
620
  # Simple selection from a single result.
@@ -693,7 +706,7 @@ EOF
693
706
  #
694
707
 
695
708
  def test_assert_select_email
696
- assert_raises(AssertionFailedError) { assert_select_email {} }
709
+ assert_raise(Assertion) { assert_select_email {} }
697
710
  AssertSelectMailer.deliver_test "<div><p>foo</p><p>bar</p></div>"
698
711
  assert_select_email do
699
712
  assert_select "div:root" do