actionpack 1.13.6 → 2.0.0

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 (317) hide show
  1. data/CHANGELOG +1400 -20
  2. data/MIT-LICENSE +1 -1
  3. data/README +5 -5
  4. data/RUNNING_UNIT_TESTS +4 -5
  5. data/Rakefile +5 -6
  6. data/install.rb +2 -2
  7. data/lib/action_controller.rb +11 -15
  8. data/lib/action_controller/assertions.rb +12 -25
  9. data/lib/action_controller/assertions/dom_assertions.rb +18 -4
  10. data/lib/action_controller/assertions/model_assertions.rb +8 -1
  11. data/lib/action_controller/assertions/response_assertions.rb +35 -12
  12. data/lib/action_controller/assertions/routing_assertions.rb +56 -12
  13. data/lib/action_controller/assertions/selector_assertions.rb +105 -38
  14. data/lib/action_controller/assertions/tag_assertions.rb +28 -15
  15. data/lib/action_controller/base.rb +318 -250
  16. data/lib/action_controller/benchmarking.rb +33 -29
  17. data/lib/action_controller/caching.rb +130 -64
  18. data/lib/action_controller/cgi_ext.rb +16 -0
  19. data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
  20. data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
  21. data/lib/action_controller/cgi_ext/session.rb +73 -0
  22. data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
  23. data/lib/action_controller/cgi_process.rb +34 -57
  24. data/lib/action_controller/components.rb +19 -36
  25. data/lib/action_controller/cookies.rb +10 -9
  26. data/lib/action_controller/dispatcher.rb +195 -0
  27. data/lib/action_controller/filters.rb +35 -34
  28. data/lib/action_controller/flash.rb +30 -35
  29. data/lib/action_controller/helpers.rb +121 -47
  30. data/lib/action_controller/http_authentication.rb +126 -0
  31. data/lib/action_controller/integration.rb +105 -101
  32. data/lib/action_controller/layout.rb +59 -47
  33. data/lib/action_controller/mime_responds.rb +57 -68
  34. data/lib/action_controller/mime_type.rb +43 -80
  35. data/lib/action_controller/mime_types.rb +20 -0
  36. data/lib/action_controller/polymorphic_routes.rb +88 -0
  37. data/lib/action_controller/record_identifier.rb +91 -0
  38. data/lib/action_controller/request.rb +553 -88
  39. data/lib/action_controller/request_forgery_protection.rb +126 -0
  40. data/lib/action_controller/request_profiler.rb +138 -0
  41. data/lib/action_controller/rescue.rb +185 -69
  42. data/lib/action_controller/resources.rb +211 -172
  43. data/lib/action_controller/response.rb +49 -8
  44. data/lib/action_controller/routing.rb +359 -236
  45. data/lib/action_controller/routing_optimisation.rb +119 -0
  46. data/lib/action_controller/session/active_record_store.rb +3 -2
  47. data/lib/action_controller/session/cookie_store.rb +161 -0
  48. data/lib/action_controller/session/mem_cache_store.rb +9 -16
  49. data/lib/action_controller/session_management.rb +17 -8
  50. data/lib/action_controller/streaming.rb +6 -3
  51. data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
  52. data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
  53. data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
  54. data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
  55. data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
  56. data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
  57. data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
  58. data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
  59. data/lib/action_controller/test_case.rb +53 -0
  60. data/lib/action_controller/test_process.rb +59 -46
  61. data/lib/action_controller/url_rewriter.rb +48 -24
  62. data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
  63. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
  64. data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
  65. data/lib/action_controller/verification.rb +27 -21
  66. data/lib/action_pack.rb +1 -1
  67. data/lib/action_pack/version.rb +4 -4
  68. data/lib/action_view.rb +2 -3
  69. data/lib/action_view/base.rb +218 -63
  70. data/lib/action_view/compiled_templates.rb +1 -2
  71. data/lib/action_view/helpers/active_record_helper.rb +35 -17
  72. data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
  73. data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
  74. data/lib/action_view/helpers/benchmark_helper.rb +12 -5
  75. data/lib/action_view/helpers/cache_helper.rb +29 -0
  76. data/lib/action_view/helpers/capture_helper.rb +97 -63
  77. data/lib/action_view/helpers/date_helper.rb +295 -35
  78. data/lib/action_view/helpers/debug_helper.rb +6 -2
  79. data/lib/action_view/helpers/form_helper.rb +354 -111
  80. data/lib/action_view/helpers/form_options_helper.rb +171 -109
  81. data/lib/action_view/helpers/form_tag_helper.rb +332 -76
  82. data/lib/action_view/helpers/javascript_helper.rb +35 -11
  83. data/lib/action_view/helpers/javascripts/controls.js +484 -354
  84. data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
  85. data/lib/action_view/helpers/javascripts/effects.js +396 -364
  86. data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
  87. data/lib/action_view/helpers/number_helper.rb +84 -60
  88. data/lib/action_view/helpers/prototype_helper.rb +419 -43
  89. data/lib/action_view/helpers/record_identification_helper.rb +20 -0
  90. data/lib/action_view/helpers/record_tag_helper.rb +59 -0
  91. data/lib/action_view/helpers/sanitize_helper.rb +223 -0
  92. data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
  93. data/lib/action_view/helpers/tag_helper.rb +69 -39
  94. data/lib/action_view/helpers/text_helper.rb +221 -148
  95. data/lib/action_view/helpers/url_helper.rb +283 -165
  96. data/lib/action_view/partials.rb +134 -62
  97. data/lib/action_view/template_error.rb +4 -12
  98. data/lib/actionpack.rb +1 -0
  99. data/test/abstract_unit.rb +21 -1
  100. data/test/action_view_test.rb +26 -0
  101. data/test/active_record_unit.rb +12 -20
  102. data/test/activerecord/active_record_store_test.rb +2 -2
  103. data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
  104. data/test/controller/action_pack_assertions_test.rb +21 -152
  105. data/test/controller/addresses_render_test.rb +2 -7
  106. data/test/controller/assert_select_test.rb +120 -14
  107. data/test/controller/base_test.rb +11 -13
  108. data/test/controller/caching_test.rb +125 -5
  109. data/test/controller/capture_test.rb +23 -16
  110. data/test/controller/cgi_test.rb +66 -391
  111. data/test/controller/components_test.rb +31 -42
  112. data/test/controller/content_type_test.rb +1 -1
  113. data/test/controller/cookie_test.rb +42 -14
  114. data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
  115. data/test/controller/dispatcher_test.rb +123 -0
  116. data/test/controller/fake_models.rb +5 -0
  117. data/test/controller/filters_test.rb +44 -7
  118. data/test/controller/flash_test.rb +46 -2
  119. data/test/controller/fragment_store_setting_test.rb +10 -8
  120. data/test/controller/helper_test.rb +19 -2
  121. data/test/controller/html-scanner/document_test.rb +124 -0
  122. data/test/controller/html-scanner/node_test.rb +69 -0
  123. data/test/controller/html-scanner/sanitizer_test.rb +250 -0
  124. data/test/controller/html-scanner/tag_node_test.rb +239 -0
  125. data/test/controller/html-scanner/text_node_test.rb +51 -0
  126. data/test/controller/html-scanner/tokenizer_test.rb +125 -0
  127. data/test/controller/http_authentication_test.rb +54 -0
  128. data/test/controller/integration_test.rb +12 -26
  129. data/test/controller/layout_test.rb +64 -12
  130. data/test/controller/mime_responds_test.rb +193 -38
  131. data/test/controller/mime_type_test.rb +30 -8
  132. data/test/controller/new_render_test.rb +104 -22
  133. data/test/controller/polymorphic_routes_test.rb +98 -0
  134. data/test/controller/record_identifier_test.rb +103 -0
  135. data/test/controller/redirect_test.rb +120 -18
  136. data/test/controller/render_test.rb +195 -45
  137. data/test/controller/request_forgery_protection_test.rb +217 -0
  138. data/test/controller/request_test.rb +545 -27
  139. data/test/controller/rescue_test.rb +501 -0
  140. data/test/controller/resources_test.rb +258 -132
  141. data/test/controller/routing_test.rb +502 -106
  142. data/test/controller/selector_test.rb +5 -5
  143. data/test/controller/send_file_test.rb +17 -7
  144. data/test/controller/session/cookie_store_test.rb +246 -0
  145. data/test/controller/session/mem_cache_store_test.rb +182 -0
  146. data/test/controller/session_fixation_test.rb +8 -11
  147. data/test/controller/session_management_test.rb +7 -7
  148. data/test/controller/test_test.rb +150 -38
  149. data/test/controller/url_rewriter_test.rb +87 -12
  150. data/test/controller/verification_test.rb +11 -0
  151. data/test/controller/view_paths_test.rb +137 -0
  152. data/test/controller/webservice_test.rb +11 -75
  153. data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
  154. data/test/fixtures/db_definitions/sqlite.sql +2 -1
  155. data/test/fixtures/developer.rb +2 -0
  156. data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
  157. data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
  158. data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
  159. data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
  160. data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
  161. data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
  162. data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
  163. data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
  164. data/test/fixtures/multipart/binary_file +0 -0
  165. data/test/fixtures/multipart/bracketed_param +5 -0
  166. data/test/fixtures/override/test/hello_world.erb +1 -0
  167. data/test/fixtures/override2/layouts/test/sub.erb +1 -0
  168. data/test/fixtures/post_test/layouts/post.html.erb +1 -0
  169. data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
  170. data/test/fixtures/post_test/post/index.html.erb +1 -0
  171. data/test/fixtures/post_test/post/index.iphone.erb +1 -0
  172. data/test/fixtures/post_test/super_post/index.html.erb +1 -0
  173. data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
  174. data/test/fixtures/public/404.html +1 -0
  175. data/test/fixtures/public/500.html +1 -0
  176. data/test/fixtures/public/javascripts/application.js +0 -1
  177. data/test/fixtures/public/javascripts/bank.js +1 -0
  178. data/test/fixtures/public/javascripts/robber.js +1 -0
  179. data/test/fixtures/public/stylesheets/bank.css +1 -0
  180. data/test/fixtures/public/stylesheets/robber.css +1 -0
  181. data/test/fixtures/replies.yml +2 -0
  182. data/test/fixtures/reply.rb +2 -1
  183. data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
  184. data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
  185. data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
  186. data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
  187. data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
  188. data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
  189. data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
  190. data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
  191. data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
  192. data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
  193. data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
  194. data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
  195. data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
  196. data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
  197. data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
  198. data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
  199. data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
  200. data/test/fixtures/test/_hash_greeting.erb +1 -0
  201. data/test/fixtures/test/_hash_object.erb +2 -0
  202. data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
  203. data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
  204. data/test/fixtures/test/_partial.erb +1 -0
  205. data/test/fixtures/test/_partial.html.erb +1 -0
  206. data/test/fixtures/test/_partial.js.erb +1 -0
  207. data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
  208. data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
  209. data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
  210. data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
  211. data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
  212. data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
  213. data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
  214. data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
  215. data/test/fixtures/test/content_for_concatenated.erb +3 -0
  216. data/test/fixtures/test/content_for_with_parameter.erb +2 -0
  217. data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
  218. data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
  219. data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
  220. data/test/fixtures/test/formatted_xml_erb.builder +1 -0
  221. data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
  222. data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
  223. data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
  224. data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
  225. data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
  226. data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
  227. data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
  228. data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
  229. data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
  230. data/test/fixtures/test/list.erb +1 -0
  231. data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
  232. data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
  233. data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
  234. data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
  235. data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
  236. data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
  237. data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
  238. data/test/fixtures/topic.rb +1 -1
  239. data/test/template/active_record_helper_test.rb +67 -20
  240. data/test/template/asset_tag_helper_test.rb +222 -54
  241. data/test/template/atom_feed_helper_test.rb +101 -0
  242. data/test/template/benchmark_helper_test.rb +2 -2
  243. data/test/template/compiled_templates_test.rb +76 -32
  244. data/test/template/date_helper_test.rb +125 -9
  245. data/test/template/form_helper_test.rb +326 -33
  246. data/test/template/form_options_helper_test.rb +822 -15
  247. data/test/template/form_tag_helper_test.rb +96 -30
  248. data/test/template/javascript_helper_test.rb +61 -13
  249. data/test/template/number_helper_test.rb +12 -11
  250. data/test/template/prototype_helper_test.rb +185 -24
  251. data/test/template/sanitize_helper_test.rb +49 -0
  252. data/test/template/scriptaculous_helper_test.rb +9 -3
  253. data/test/template/tag_helper_test.rb +13 -2
  254. data/test/template/text_helper_test.rb +38 -52
  255. data/test/template/url_helper_test.rb +216 -46
  256. metadata +144 -116
  257. data/examples/.htaccess +0 -24
  258. data/examples/address_book/index.rhtml +0 -33
  259. data/examples/address_book/layout.rhtml +0 -8
  260. data/examples/address_book_controller.cgi +0 -9
  261. data/examples/address_book_controller.fcgi +0 -6
  262. data/examples/address_book_controller.rb +0 -52
  263. data/examples/address_book_controller.rbx +0 -4
  264. data/examples/benchmark.rb +0 -52
  265. data/examples/benchmark_with_ar.fcgi +0 -89
  266. data/examples/blog_controller.cgi +0 -53
  267. data/examples/debate/index.rhtml +0 -14
  268. data/examples/debate/new_topic.rhtml +0 -22
  269. data/examples/debate/topic.rhtml +0 -32
  270. data/examples/debate_controller.cgi +0 -57
  271. data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
  272. data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
  273. data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
  274. data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
  275. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
  276. data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
  277. data/lib/action_controller/deprecated_dependencies.rb +0 -65
  278. data/lib/action_controller/deprecated_redirects.rb +0 -17
  279. data/lib/action_controller/deprecated_request_methods.rb +0 -34
  280. data/lib/action_controller/macros/auto_complete.rb +0 -53
  281. data/lib/action_controller/macros/in_place_editing.rb +0 -33
  282. data/lib/action_controller/pagination.rb +0 -408
  283. data/lib/action_controller/scaffolding.rb +0 -189
  284. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
  285. data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
  286. data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
  287. data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
  288. data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
  289. data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
  290. data/lib/action_controller/vendor/xml_node.rb +0 -97
  291. data/lib/action_view/helpers/deprecated_helper.rb +0 -37
  292. data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
  293. data/lib/action_view/helpers/pagination_helper.rb +0 -86
  294. data/test/activerecord/active_record_assertions_test.rb +0 -92
  295. data/test/activerecord/pagination_test.rb +0 -165
  296. data/test/controller/deprecated_instance_variables_test.rb +0 -48
  297. data/test/controller/raw_post_test.rb +0 -68
  298. data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
  299. data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
  300. data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
  301. data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
  302. data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
  303. data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
  304. data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
  305. data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
  306. data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
  307. data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
  308. data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
  309. data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
  310. data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
  311. data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
  312. data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
  313. data/test/fixtures/test/_hash_object.rhtml +0 -1
  314. data/test/fixtures/test/list.rhtml +0 -1
  315. data/test/template/deprecated_helper_test.rb +0 -36
  316. data/test/template/deprecated_instance_variables_test.rb +0 -43
  317. data/test/template/java_script_macros_helper_test.rb +0 -109
@@ -9,12 +9,37 @@ end
9
9
  class ThreadsController < ResourcesController; end
10
10
  class MessagesController < ResourcesController; end
11
11
  class CommentsController < ResourcesController; end
12
+ class AuthorsController < ResourcesController; end
13
+ class LogosController < ResourcesController; end
12
14
 
13
- class AccountController < ResourcesController; end
14
- class AdminController < ResourcesController; end
15
- class ProductsController < ResourcesController; end
15
+ class AccountsController < ResourcesController; end
16
+ class AdminController < ResourcesController; end
17
+
18
+ module Backoffice
19
+ class ProductsController < ResourcesController; end
20
+ class TagsController < ResourcesController; end
21
+ class ManufacturersController < ResourcesController; end
22
+ class ImagesController < ResourcesController; end
23
+
24
+ module Admin
25
+ class ProductsController < ResourcesController; end
26
+ class ImagesController < ResourcesController; end
27
+ end
28
+ end
16
29
 
17
30
  class ResourcesTest < Test::Unit::TestCase
31
+
32
+
33
+ # The assertions in these tests are incompatible with the hash method
34
+ # optimisation. This could indicate user level problems
35
+ def setup
36
+ ActionController::Base.optimise_named_routes = false
37
+ end
38
+
39
+ def tear_down
40
+ ActionController::Base.optimise_named_routes = true
41
+ end
42
+
18
43
  def test_should_arrange_actions
19
44
  resource = ActionController::Resources::Resource.new(:messages,
20
45
  :collection => { :rss => :get, :reorder => :post, :csv => :post },
@@ -58,6 +83,37 @@ class ResourcesTest < Test::Unit::TestCase
58
83
  end
59
84
  end
60
85
 
86
+ def test_with_custom_conditions
87
+ with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
88
+ assert_equal 'app', ActionController::Routing::Routes.named_routes.routes[:messages].conditions[:subdomain]
89
+ end
90
+ end
91
+
92
+ def test_irregular_id_with_no_requirements_should_raise_error
93
+ expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'}
94
+
95
+ with_restful_routing :messages do
96
+ assert_raises(ActionController::RoutingError) do
97
+ assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get)
98
+ end
99
+ end
100
+ end
101
+
102
+ def test_irregular_id_with_requirements_should_pass
103
+ expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'}
104
+
105
+ with_restful_routing(:messages, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}) do
106
+ assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get)
107
+ end
108
+ end
109
+
110
+ def test_with_path_prefix_requirements
111
+ expected_options = {:controller => 'messages', :action => 'show', :thread_id => '1.1.1', :id => '1'}
112
+ with_restful_routing :messages, :path_prefix => '/thread/:thread_id', :requirements => {:thread_id => /[0-9]\.[0-9]\.[0-9]/} do
113
+ assert_recognizes(expected_options, :path => 'thread/1.1.1/messages/1', :method => :get)
114
+ end
115
+ end
116
+
61
117
  def test_with_path_prefix
62
118
  with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do
63
119
  assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }
@@ -77,22 +133,17 @@ class ResourcesTest < Test::Unit::TestCase
77
133
  end
78
134
  end
79
135
 
80
- def test_with_collection_action
81
- rss_options = {:action => 'rss'}
82
- rss_path = "/messages/rss"
83
- actions = { 'a' => :put, 'b' => :post, 'c' => :delete }
136
+ def test_with_collection_actions
137
+ actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
84
138
 
85
- with_restful_routing :messages, :collection => { :rss => :get }.merge(actions) do
139
+ with_restful_routing :messages, :collection => actions do
86
140
  assert_restful_routes_for :messages do |options|
87
- assert_routing rss_path, options.merge(rss_options)
88
-
89
141
  actions.each do |action, method|
90
142
  assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method)
91
143
  end
92
144
  end
93
145
 
94
146
  assert_restful_named_routes_for :messages do |options|
95
- assert_named_route rss_path, :rss_messages_path, rss_options
96
147
  actions.keys.each do |action|
97
148
  assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action
98
149
  end
@@ -100,6 +151,42 @@ class ResourcesTest < Test::Unit::TestCase
100
151
  end
101
152
  end
102
153
 
154
+ def test_with_collection_actions_and_name_prefix
155
+ actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
156
+
157
+ with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do
158
+ assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
159
+ actions.each do |action, method|
160
+ assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method)
161
+ end
162
+ end
163
+
164
+ assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
165
+ actions.keys.each do |action|
166
+ assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", :action => action
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ def test_with_collection_action_and_name_prefix_and_formatted
173
+ actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
174
+
175
+ with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do
176
+ assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
177
+ actions.each do |action, method|
178
+ assert_recognizes(options.merge(:action => action, :format => 'xml'), :path => "/threads/1/messages/#{action}.xml", :method => method)
179
+ end
180
+ end
181
+
182
+ assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
183
+ actions.keys.each do |action|
184
+ assert_named_route "/threads/1/messages/#{action}.xml", "formatted_#{action}_thread_messages_path", :action => action, :format => 'xml'
185
+ end
186
+ end
187
+ end
188
+ end
189
+
103
190
  def test_with_member_action
104
191
  [:put, :post].each do |method|
105
192
  with_restful_routing :messages, :member => { :mark => method } do
@@ -147,12 +234,40 @@ class ResourcesTest < Test::Unit::TestCase
147
234
  end
148
235
  end
149
236
  end
237
+
238
+ def test_with_new_action_with_name_prefix
239
+ with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do
240
+ preview_options = {:action => 'preview', :thread_id => '1'}
241
+ preview_path = "/threads/1/messages/new/preview"
242
+ assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
243
+ assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post)
244
+ end
245
+
246
+ assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
247
+ assert_named_route preview_path, :preview_new_thread_message_path, preview_options
248
+ end
249
+ end
250
+ end
251
+
252
+ def test_with_formatted_new_action_with_name_prefix
253
+ with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do
254
+ preview_options = {:action => 'preview', :thread_id => '1', :format => 'xml'}
255
+ preview_path = "/threads/1/messages/new/preview.xml"
256
+ assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
257
+ assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post)
258
+ end
150
259
 
260
+ assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
261
+ assert_named_route preview_path, :formatted_preview_new_thread_message_path, preview_options
262
+ end
263
+ end
264
+ end
265
+
151
266
  def test_override_new_method
152
267
  with_restful_routing :messages do
153
268
  assert_restful_routes_for :messages do |options|
154
269
  assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
155
- assert_raises(ActionController::RoutingError) do
270
+ assert_raises(ActionController::MethodNotAllowed) do
156
271
  ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
157
272
  end
158
273
  end
@@ -178,12 +293,32 @@ class ResourcesTest < Test::Unit::TestCase
178
293
 
179
294
  assert_simply_restful_for :threads
180
295
  assert_simply_restful_for :messages,
181
- :path_prefix => 'threads/1/',
182
296
  :name_prefix => 'thread_',
297
+ :path_prefix => 'threads/1/',
183
298
  :options => { :thread_id => '1' }
184
299
  assert_simply_restful_for :comments,
185
- :path_prefix => 'threads/1/messages/2/',
186
300
  :name_prefix => 'thread_message_',
301
+ :path_prefix => 'threads/1/messages/2/',
302
+ :options => { :thread_id => '1', :message_id => '2' }
303
+ end
304
+ end
305
+
306
+ def test_nested_restful_routes_with_overwritten_defaults
307
+ with_routing do |set|
308
+ set.draw do |map|
309
+ map.resources :threads do |map|
310
+ map.resources :messages, :name_prefix => nil do |map|
311
+ map.resources :comments, :name_prefix => nil
312
+ end
313
+ end
314
+ end
315
+
316
+ assert_simply_restful_for :threads
317
+ assert_simply_restful_for :messages,
318
+ :path_prefix => 'threads/1/',
319
+ :options => { :thread_id => '1' }
320
+ assert_simply_restful_for :comments,
321
+ :path_prefix => 'threads/1/messages/2/',
187
322
  :options => { :thread_id => '1', :message_id => '2' }
188
323
  end
189
324
  end
@@ -207,22 +342,45 @@ class ResourcesTest < Test::Unit::TestCase
207
342
  end
208
343
 
209
344
  def test_should_create_multiple_singleton_resource_routes
210
- with_singleton_resources :account, :admin do
345
+ with_singleton_resources :account, :logo do
211
346
  assert_singleton_restful_for :account
212
- assert_singleton_restful_for :admin
347
+ assert_singleton_restful_for :logo
213
348
  end
214
349
  end
215
350
 
216
351
  def test_should_create_nested_singleton_resource_routes
217
352
  with_routing do |set|
218
353
  set.draw do |map|
219
- map.resource :admin do |admin|
354
+ map.resource :admin, :controller => 'admin' do |admin|
220
355
  admin.resource :account
221
356
  end
222
357
  end
223
358
 
224
- assert_singleton_restful_for :admin
225
- assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_'
359
+ assert_singleton_restful_for :admin, :controller => 'admin'
360
+ assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => 'admin/'
361
+ end
362
+ end
363
+
364
+ def test_resource_has_many_should_become_nested_resources
365
+ with_routing do |set|
366
+ set.draw do |map|
367
+ map.resources :messages, :has_many => [ :comments, :authors ]
368
+ end
369
+
370
+ assert_simply_restful_for :messages
371
+ assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' }
372
+ assert_simply_restful_for :authors, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' }
373
+ end
374
+ end
375
+
376
+ def test_resource_has_one_should_become_nested_resources
377
+ with_routing do |set|
378
+ set.draw do |map|
379
+ map.resources :messages, :has_one => :logo
380
+ end
381
+
382
+ assert_simply_restful_for :messages
383
+ assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :options => { :message_id => '1' }
226
384
  end
227
385
  end
228
386
 
@@ -269,7 +427,7 @@ class ResourcesTest < Test::Unit::TestCase
269
427
  end
270
428
 
271
429
  assert_singleton_restful_for :account
272
- assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_'
430
+ assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => 'account/'
273
431
  end
274
432
  end
275
433
 
@@ -282,7 +440,7 @@ class ResourcesTest < Test::Unit::TestCase
282
440
  end
283
441
 
284
442
  assert_singleton_restful_for :account, :path_prefix => '7/', :options => { :site_id => '7' }
285
- assert_simply_restful_for :messages, :path_prefix => '7/account/', :name_prefix => 'account_', :options => { :site_id => '7' }
443
+ assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => '7/account/', :options => { :site_id => '7' }
286
444
  end
287
445
  end
288
446
 
@@ -290,12 +448,12 @@ class ResourcesTest < Test::Unit::TestCase
290
448
  with_routing do |set|
291
449
  set.draw do |map|
292
450
  map.resources :threads do |thread|
293
- thread.resource :admin
451
+ thread.resource :admin, :controller => 'admin'
294
452
  end
295
453
  end
296
454
 
297
455
  assert_simply_restful_for :threads
298
- assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' }
456
+ assert_singleton_restful_for :admin, :controller => 'admin', :name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' }
299
457
  end
300
458
  end
301
459
 
@@ -305,11 +463,11 @@ class ResourcesTest < Test::Unit::TestCase
305
463
  options = { :controller => controller_name.to_s }
306
464
  collection_path = "/#{controller_name}"
307
465
 
308
- assert_raises(ActionController::RoutingError) do
466
+ assert_raises(ActionController::MethodNotAllowed) do
309
467
  assert_recognizes(options.merge(:action => 'update'), :path => collection_path, :method => :put)
310
468
  end
311
469
 
312
- assert_raises(ActionController::RoutingError) do
470
+ assert_raises(ActionController::MethodNotAllowed) do
313
471
  assert_recognizes(options.merge(:action => 'destroy'), :path => collection_path, :method => :delete)
314
472
  end
315
473
  end
@@ -321,9 +479,9 @@ class ResourcesTest < Test::Unit::TestCase
321
479
  map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'
322
480
  map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'
323
481
  end
324
-
482
+
325
483
  action_separator = ActionController::Base.resource_action_separator
326
-
484
+
327
485
  assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
328
486
  assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {}
329
487
  assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}
@@ -359,134 +517,95 @@ class ResourcesTest < Test::Unit::TestCase
359
517
  end
360
518
  end
361
519
 
362
- def test_should_add_deprecated_named_routes_for_resource
520
+ def test_resources_in_namespace
363
521
  with_routing do |set|
364
522
  set.draw do |map|
365
- map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'
366
- end
367
- assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
368
- assert_deprecated do
369
- assert_named_route "/threads/1/messages/search", "thread_search_messages_path", {}
370
- assert_named_route "/threads/1/messages/new", "thread_new_message_path", {}
371
- assert_named_route "/threads/1/messages/new/preview", "thread_preview_new_message_path", {}
523
+ map.namespace :backoffice do |backoffice|
524
+ backoffice.resources :products
525
+ end
372
526
  end
527
+
528
+ assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
373
529
  end
374
530
  end
375
531
 
376
- def test_should_add_deprecated_named_routes_for_singleton_resource
532
+ def test_resource_has_many_in_namespace
377
533
  with_routing do |set|
378
534
  set.draw do |map|
379
- map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'
380
- end
381
- assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'
382
- assert_deprecated do
383
- assert_named_route "/admin/account/login", "admin_login_account_path", {}
384
- assert_named_route "/admin/account/new", "admin_new_account_path", {}
385
- assert_named_route "/admin/account/new/preview", "admin_preview_new_account_path", {}
535
+ map.namespace :backoffice do |backoffice|
536
+ backoffice.resources :products, :has_many => :tags
537
+ end
386
538
  end
539
+
540
+ assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
541
+ assert_simply_restful_for :tags, :controller => "backoffice/tags", :name_prefix => "backoffice_product_", :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }
387
542
  end
388
543
  end
389
544
 
390
- def test_should_add_deprecated_named_routes_for_nested_resources
545
+ def test_resource_has_one_in_namespace
391
546
  with_routing do |set|
392
547
  set.draw do |map|
393
- map.resources :threads do |map|
394
- map.resources :messages do |map|
395
- map.resources :comments
396
- end
548
+ map.namespace :backoffice do |backoffice|
549
+ backoffice.resources :products, :has_one => :manufacturer
397
550
  end
398
551
  end
399
552
 
400
- assert_simply_restful_for :threads
401
- assert_simply_restful_for :messages,
402
- :path_prefix => 'threads/1/',
403
- :name_prefix => 'thread_',
404
- :options => { :thread_id => '1' }
405
- assert_simply_restful_for :comments,
406
- :path_prefix => 'threads/1/messages/2/',
407
- :name_prefix => 'thread_message_',
408
- :options => { :thread_id => '1', :message_id => '2' }
409
-
410
- assert_deprecated do
411
- assert_named_route "/threads/1/messages", "messages_path", {}
412
- assert_named_route "/threads/1/messages/1", "message_path", {:thread_id => '1', :id => '1'}
413
- assert_named_route "/threads/1/messages/new", "new_message_path", {:thread_id => '1'}
414
- assert_named_route "/threads/1/messages/1/edit", "edit_message_path", {:thread_id => '1', :id => '1'}
415
- end
553
+ assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
554
+ assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturers", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }
416
555
  end
417
556
  end
418
557
 
419
- def test_should_add_deprecated_named_routes_for_nested_singleton_resources
558
+ def test_resources_in_nested_namespace
420
559
  with_routing do |set|
421
560
  set.draw do |map|
422
- map.resource :admin do |admin|
423
- admin.resource :account
561
+ map.namespace :backoffice do |backoffice|
562
+ backoffice.namespace :admin do |admin|
563
+ admin.resources :products
564
+ end
424
565
  end
425
566
  end
426
567
 
427
- assert_singleton_restful_for :admin
428
- assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_'
429
-
430
- assert_deprecated do
431
- assert_named_route "/admin/account", "account_path", {}
432
- assert_named_route "/admin/account/new", "new_account_path", {}
433
- assert_named_route "/admin/account/edit", "edit_account_path", {}
434
- end
568
+ assert_simply_restful_for :products, :controller => "backoffice/admin/products", :name_prefix => 'backoffice_admin_', :path_prefix => 'backoffice/admin/'
435
569
  end
436
570
  end
437
571
 
438
- def test_should_add_deprecated_named_routes_for_nested_resources_in_singleton_resource
572
+ def test_resources_using_namespace
439
573
  with_routing do |set|
440
574
  set.draw do |map|
441
- map.resource :account do |account|
442
- account.resources :messages
443
- end
575
+ map.resources :products, :namespace => "backoffice/"
444
576
  end
445
577
 
446
- assert_singleton_restful_for :account
447
- assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_'
448
-
449
- assert_deprecated do
450
- assert_named_route "/account/messages", "messages_path", {}
451
- assert_named_route "/account/messages/1", "message_path", {:id => '1'}
452
- assert_named_route "/account/messages/new", "new_message_path", {}
453
- assert_named_route "/account/messages/1/edit", "edit_message_path", {:id => '1'}
454
- end
578
+ assert_simply_restful_for :products, :controller => "backoffice/products"
455
579
  end
456
580
  end
457
-
458
- def test_should_add_deprecated_named_routes_for_nested_singleton_resource_in_resources
581
+
582
+ def test_nested_resources_using_namespace
459
583
  with_routing do |set|
460
584
  set.draw do |map|
461
- map.resources :threads do |thread|
462
- thread.resource :admin
585
+ map.namespace :backoffice do |backoffice|
586
+ backoffice.resources :products do |products|
587
+ products.resources :images
588
+ end
463
589
  end
464
590
  end
465
591
 
466
- assert_simply_restful_for :threads
467
- assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' }
468
-
469
- assert_deprecated do
470
- assert_named_route "/threads/5/admin", "admin_path", {}
471
- assert_named_route "/threads/5/admin/new", "new_admin_path", {}
472
- assert_named_route "/threads/5/admin/edit", "edit_admin_path", {}
473
- end
592
+ assert_simply_restful_for :images, :controller => "backoffice/images", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => {:product_id => '1'}
474
593
  end
475
594
  end
476
595
 
477
- def test_should_add_deprecated_formatted_routes
596
+ def test_nested_resources_in_nested_namespace
478
597
  with_routing do |set|
479
598
  set.draw do |map|
480
- map.resources :products, :collection => { :specials => :get }, :member => { :thumbnail => :get }
481
- map.resource :account, :member => { :icon => :get }
482
- end
483
- assert_restful_routes_for :products do |options|
484
- assert_recognizes options.merge({ :action => 'specials', :format => 'xml' }), :path => '/products.xml;specials', :method => :get
485
- assert_recognizes options.merge({ :action => 'thumbnail', :format => 'jpg', :id => '1' }), :path => '/products/1.jpg;thumbnail', :method => :get
486
- end
487
- assert_singleton_restful_for :account do |options|
488
- assert_recognizes options.merge({ :action => 'icon', :format => 'jpg' }), :path => '/account.jpg;icon', :method => :get
599
+ map.namespace :backoffice do |backoffice|
600
+ backoffice.namespace :admin do |admin|
601
+ admin.resources :products do |products|
602
+ products.resources :images
603
+ end
604
+ end
605
+ end
489
606
  end
607
+
608
+ assert_simply_restful_for :images, :controller => "backoffice/admin/images", :name_prefix => 'backoffice_admin_product_', :path_prefix => 'backoffice/admin/products/1/', :options => {:product_id => '1'}
490
609
  end
491
610
  end
492
611
 
@@ -508,7 +627,7 @@ class ResourcesTest < Test::Unit::TestCase
508
627
  # runs assert_restful_routes_for and assert_restful_named_routes for on the controller_name and options, without passing a block.
509
628
  def assert_simply_restful_for(controller_name, options = {})
510
629
  assert_restful_routes_for controller_name, options
511
- assert_restful_named_routes_for controller_name, options
630
+ assert_restful_named_routes_for controller_name, nil, options
512
631
  end
513
632
 
514
633
  def assert_singleton_restful_for(singleton_name, options = {})
@@ -517,7 +636,8 @@ class ResourcesTest < Test::Unit::TestCase
517
636
  end
518
637
 
519
638
  def assert_restful_routes_for(controller_name, options = {})
520
- (options[:options] ||= {})[:controller] = controller_name.to_s
639
+ options[:options] ||= {}
640
+ options[:options][:controller] = options[:controller] || controller_name.to_s
521
641
 
522
642
  collection_path = "/#{options[:path_prefix]}#{controller_name}"
523
643
  member_path = "#{collection_path}/1"
@@ -562,8 +682,11 @@ class ResourcesTest < Test::Unit::TestCase
562
682
  singular_name = nil
563
683
  end
564
684
  singular_name ||= controller_name.to_s.singularize
565
- (options[:options] ||= {})[:controller] = controller_name.to_s
566
- @controller = "#{controller_name.to_s.camelize}Controller".constantize.new
685
+
686
+ options[:options] ||= {}
687
+ options[:options][:controller] = options[:controller] || controller_name.to_s
688
+
689
+ @controller = "#{options[:options][:controller].camelize}Controller".constantize.new
567
690
  @request = ActionController::TestRequest.new
568
691
  @response = ActionController::TestResponse.new
569
692
  get :index, options[:options]
@@ -571,20 +694,23 @@ class ResourcesTest < Test::Unit::TestCase
571
694
 
572
695
  full_prefix = "/#{options[:path_prefix]}#{controller_name}"
573
696
  name_prefix = options[:name_prefix]
574
-
697
+
575
698
  assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options]
576
- assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options]
577
- assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
578
- assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
579
699
  assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml')
580
- assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
700
+ assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
581
701
  assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
702
+
703
+ assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options]
704
+ assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
705
+ assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
582
706
  assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
707
+
583
708
  yield options[:options] if block_given?
584
709
  end
585
-
710
+
586
711
  def assert_singleton_routes_for(singleton_name, options = {})
587
- (options[:options] ||= {})[:controller] ||= singleton_name.to_s
712
+ options[:options] ||= {}
713
+ options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize
588
714
 
589
715
  full_path = "/#{options[:path_prefix]}#{singleton_name}"
590
716
  new_path = "#{full_path}/new"
@@ -618,7 +744,7 @@ class ResourcesTest < Test::Unit::TestCase
618
744
  end
619
745
 
620
746
  def assert_singleton_named_routes_for(singleton_name, options = {})
621
- (options[:options] ||= {})[:controller] ||= singleton_name.to_s
747
+ (options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize
622
748
  @controller = "#{options[:options][:controller].camelize}Controller".constantize.new
623
749
  @request = ActionController::TestRequest.new
624
750
  @response = ActionController::TestResponse.new
@@ -626,21 +752,22 @@ class ResourcesTest < Test::Unit::TestCase
626
752
  options[:options].delete :action
627
753
 
628
754
  full_path = "/#{options[:path_prefix]}#{singleton_name}"
629
- full_name = "#{options[:name_prefix]}#{singleton_name}"
755
+ name_prefix = options[:name_prefix]
630
756
 
631
- assert_named_route "#{full_path}", "#{full_name}_path", options[:options]
632
- assert_named_route "#{full_path}/new", "new_#{full_name}_path", options[:options]
633
- assert_named_route "#{full_path}/edit", "edit_#{full_name}_path", options[:options]
634
- assert_named_route "#{full_path}.xml", "formatted_#{full_name}_path", options[:options].merge(:format => 'xml')
635
- assert_named_route "#{full_path}/new.xml", "formatted_new_#{full_name}_path", options[:options].merge(:format => 'xml')
636
- assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{full_name}_path", options[:options].merge(:format => 'xml')
757
+ assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", options[:options]
758
+ assert_named_route "#{full_path}.xml", "formatted_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
759
+
760
+ assert_named_route "#{full_path}/new", "new_#{name_prefix}#{singleton_name}_path", options[:options]
761
+ assert_named_route "#{full_path}/new.xml", "formatted_new_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
762
+ assert_named_route "#{full_path}/edit", "edit_#{name_prefix}#{singleton_name}_path", options[:options]
763
+ assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
637
764
  end
638
765
 
639
766
  def assert_named_route(expected, route, options)
640
767
  actual = @controller.send(route, options) rescue $!.class.name
641
768
  assert_equal expected, actual, "Error on route: #{route}(#{options.inspect})"
642
769
  end
643
-
770
+
644
771
  def assert_resource_methods(expected, resource, action_method, method)
645
772
  assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}"
646
773
  expected.each do |action|
@@ -657,5 +784,4 @@ class ResourcesTest < Test::Unit::TestCase
657
784
  end
658
785
  true
659
786
  end
660
-
661
- end
787
+ end