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
@@ -0,0 +1,24 @@
1
+ <% unless @exception.blamed_files.blank? %>
2
+ <% if (hide = @exception.blamed_files.length > 8) %>
3
+ <a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a>
4
+ <% end %>
5
+ <pre id="blame_trace" <%='style="display:none"' if hide %>><code><%=h @exception.describe_blame %></code></pre>
6
+ <% end %>
7
+
8
+ <%
9
+ clean_params = request.parameters.clone
10
+ clean_params.delete("action")
11
+ clean_params.delete("controller")
12
+
13
+ request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
14
+ %>
15
+
16
+ <h2 style="margin-top: 30px">Request</h2>
17
+ <p><b>Parameters</b>: <pre><%=h request_dump %></pre></p>
18
+
19
+ <p><a href="#" onclick="document.getElementById('session_dump').style.display='block'; return false;">Show session dump</a></p>
20
+ <div id="session_dump" style="display:none"><%= debug(request.session.instance_variable_get("@data")) %></div>
21
+
22
+
23
+ <h2 style="margin-top: 30px">Response</h2>
24
+ <p><b>Headers</b>: <pre><%=h response ? response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p>
@@ -6,6 +6,6 @@
6
6
  </h1>
7
7
  <pre><%=h @exception.clean_message %></pre>
8
8
 
9
- <%= render_file(@rescues_path + "/_trace.rhtml", false) %>
9
+ <%= render_file(@rescues_path + "/_trace.erb", false) %>
10
10
 
11
- <%= render_file(@rescues_path + "/_request_and_response.rhtml", false) %>
11
+ <%= render_file(@rescues_path + "/_request_and_response.erb", false) %>
@@ -15,7 +15,7 @@
15
15
 
16
16
  <% @real_exception = @exception
17
17
  @exception = @exception.original_exception || @exception %>
18
- <%= render_file(@rescues_path + "/_trace.rhtml", false) %>
18
+ <%= render_file(@rescues_path + "/_trace.erb", false) %>
19
19
  <% @exception = @real_exception %>
20
20
 
21
- <%= render_file(@rescues_path + "/_request_and_response.rhtml", false) %>
21
+ <%= render_file(@rescues_path + "/_request_and_response.erb", false) %>
@@ -0,0 +1,53 @@
1
+ require 'active_support/test_case'
2
+
3
+ module ActionController
4
+ class NonInferrableControllerError < ActionControllerError
5
+ def initialize(name)
6
+ super "Unable to determine the controller to test from #{name}. " +
7
+ "You'll need to specify it using 'tests YourController' in your " +
8
+ "test case definition"
9
+ end
10
+ end
11
+
12
+ class TestCase < ActiveSupport::TestCase
13
+ @@controller_class = nil
14
+ class << self
15
+ def tests(controller_class)
16
+ self.controller_class = controller_class
17
+ end
18
+
19
+ def controller_class=(new_class)
20
+ prepare_controller_class(new_class)
21
+ write_inheritable_attribute(:controller_class, new_class)
22
+ end
23
+
24
+ def controller_class
25
+ if current_controller_class = read_inheritable_attribute(:controller_class)
26
+ current_controller_class
27
+ else
28
+ self.controller_class= determine_default_controller_class(name)
29
+ end
30
+ end
31
+
32
+ def determine_default_controller_class(name)
33
+ name.sub(/Test$/, '').constantize
34
+ rescue NameError
35
+ raise NonInferrableControllerError.new(name)
36
+ end
37
+
38
+ def prepare_controller_class(new_class)
39
+ new_class.class_eval do
40
+ def rescue_action(e)
41
+ raise e
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def setup
48
+ @controller = self.class.controller_class.new
49
+ @request = TestRequest.new
50
+ @response = TestResponse.new
51
+ end
52
+ end
53
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/assertions'
1
+ require 'action_controller/assertions'
2
2
 
3
3
  module ActionController #:nodoc:
4
4
  class Base
@@ -23,8 +23,7 @@ module ActionController #:nodoc:
23
23
  class TestRequest < AbstractRequest #:nodoc:
24
24
  attr_accessor :cookies, :session_options
25
25
  attr_accessor :query_parameters, :request_parameters, :path, :session, :env
26
- attr_accessor :host
27
- attr_reader :request_uri_overridden
26
+ attr_accessor :host, :user_agent
28
27
 
29
28
  def initialize(query_parameters = nil, request_parameters = nil, session = nil)
30
29
  @query_parameters = query_parameters || {}
@@ -41,18 +40,15 @@ module ActionController #:nodoc:
41
40
  @session = TestSession.new
42
41
  end
43
42
 
43
+ # Wraps raw_post in a StringIO.
44
+ def body
45
+ StringIO.new(raw_post)
46
+ end
47
+
48
+ # Either the RAW_POST_DATA environment variable or the URL-encoded request
49
+ # parameters.
44
50
  def raw_post
45
- if raw_post = env['RAW_POST_DATA']
46
- raw_post
47
- else
48
- params = self.request_parameters.dup
49
- %w(controller action only_path).each do |k|
50
- params.delete(k)
51
- params.delete(k.to_sym)
52
- end
53
-
54
- params.map { |k,v| [ CGI.escape(k.to_s), CGI.escape(v.to_s) ].join('=') }.sort.join('&')
55
- end
51
+ env['RAW_POST_DATA'] ||= url_encoded_request_parameters
56
52
  end
57
53
 
58
54
  def port=(number)
@@ -68,14 +64,12 @@ module ActionController #:nodoc:
68
64
  # Used to check AbstractRequest's request_uri functionality.
69
65
  # Disables the use of @path and @request_uri so superclass can handle those.
70
66
  def set_REQUEST_URI(value)
71
- @request_uri_overridden = true
72
67
  @env["REQUEST_URI"] = value
73
68
  @request_uri = nil
74
69
  @path = nil
75
70
  end
76
71
 
77
72
  def request_uri=(uri)
78
- @env["REQUEST_URI"] = uri
79
73
  @request_uri = uri
80
74
  @path = uri.split("?").first
81
75
  end
@@ -93,11 +87,11 @@ module ActionController #:nodoc:
93
87
  end
94
88
 
95
89
  def request_uri
96
- @request_uri || super()
90
+ @request_uri || super
97
91
  end
98
92
 
99
93
  def path
100
- @path || super()
94
+ @path || super
101
95
  end
102
96
 
103
97
  def assign_parameters(controller_path, action, parameters)
@@ -127,6 +121,10 @@ module ActionController #:nodoc:
127
121
  @request_method, @accepts, @content_type = nil, nil, nil
128
122
  end
129
123
 
124
+ def referer
125
+ @env["HTTP_REFERER"]
126
+ end
127
+
130
128
  private
131
129
  def initialize_containers
132
130
  @env, @cookies = {}, {}
@@ -135,10 +133,22 @@ module ActionController #:nodoc:
135
133
  def initialize_default_values
136
134
  @host = "test.host"
137
135
  @request_uri = "/"
136
+ @user_agent = "Rails Testing"
138
137
  self.remote_addr = "0.0.0.0"
139
138
  @env["SERVER_PORT"] = 80
140
139
  @env['REQUEST_METHOD'] = "GET"
141
140
  end
141
+
142
+ def url_encoded_request_parameters
143
+ params = self.request_parameters.dup
144
+
145
+ %w(controller action only_path).each do |k|
146
+ params.delete(k)
147
+ params.delete(k.to_sym)
148
+ end
149
+
150
+ params.to_query
151
+ end
142
152
  end
143
153
 
144
154
  # A refactoring of TestResponse to allow the same behavior to be applied
@@ -260,13 +270,7 @@ module ActionController #:nodoc:
260
270
  require 'stringio'
261
271
 
262
272
  sio = StringIO.new
263
-
264
- begin
265
- $stdout = sio
266
- body.call
267
- ensure
268
- $stdout = STDOUT
269
- end
273
+ body.call(self, sio)
270
274
 
271
275
  sio.rewind
272
276
  sio.read
@@ -320,33 +324,37 @@ module ActionController #:nodoc:
320
324
  #
321
325
  # Usage example, within a functional test:
322
326
  # post :change_avatar, :avatar => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/spongebob.png', 'image/png')
327
+ #
328
+ # Pass a true third parameter to ensure the uploaded file is opened in binary mode (only required for Windows):
329
+ # post :change_avatar, :avatar => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/spongebob.png', 'image/png', :binary)
323
330
  require 'tempfile'
324
331
  class TestUploadedFile
325
332
  # The filename, *not* including the path, of the "uploaded" file
326
333
  attr_reader :original_filename
327
-
334
+
328
335
  # The content type of the "uploaded" file
329
336
  attr_reader :content_type
330
-
331
- def initialize(path, content_type = 'text/plain')
337
+
338
+ def initialize(path, content_type = Mime::TEXT, binary = false)
332
339
  raise "#{path} file does not exist" unless File.exist?(path)
333
340
  @content_type = content_type
334
341
  @original_filename = path.sub(/^.*#{File::SEPARATOR}([^#{File::SEPARATOR}]+)$/) { $1 }
335
342
  @tempfile = Tempfile.new(@original_filename)
343
+ @tempfile.binmode if binary
336
344
  FileUtils.copy_file(path, @tempfile.path)
337
345
  end
338
-
346
+
339
347
  def path #:nodoc:
340
348
  @tempfile.path
341
349
  end
342
-
350
+
343
351
  alias local_path path
344
-
352
+
345
353
  def method_missing(method_name, *args, &block) #:nodoc:
346
- @tempfile.send(method_name, *args, &block)
354
+ @tempfile.send!(method_name, *args, &block)
347
355
  end
348
356
  end
349
-
357
+
350
358
  module TestProcess
351
359
  def self.included(base)
352
360
  # execute the request simulating a specific http method and set/volley the response
@@ -365,7 +373,7 @@ module ActionController #:nodoc:
365
373
  # Sanity check for required instance variables so we can give an
366
374
  # understandable error message.
367
375
  %w(@controller @request @response).each do |iv_name|
368
- if !instance_variables.include?(iv_name) || instance_variable_get(iv_name).nil?
376
+ if !(instance_variables.include?(iv_name) || instance_variables.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
369
377
  raise "#{iv_name} is nil: make sure you set it in your test's setup method."
370
378
  end
371
379
  end
@@ -388,7 +396,7 @@ module ActionController #:nodoc:
388
396
  def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
389
397
  @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
390
398
  @request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
391
- returning self.send(request_method, action, parameters, session, flash) do
399
+ returning send!(request_method, action, parameters, session, flash) do
392
400
  @request.env.delete 'HTTP_X_REQUESTED_WITH'
393
401
  @request.env.delete 'HTTP_ACCEPT'
394
402
  end
@@ -429,17 +437,18 @@ module ActionController #:nodoc:
429
437
  end
430
438
 
431
439
  def build_request_uri(action, parameters)
432
- unless @request.request_uri_overridden
433
- options = @controller.send(:rewrite_options, parameters)
440
+ unless @request.env['REQUEST_URI']
441
+ options = @controller.send!(:rewrite_options, parameters)
434
442
  options.update(:only_path => true, :action => action)
435
443
 
436
444
  url = ActionController::UrlRewriter.new(@request, parameters)
437
- @request.request_uri = url.rewrite(options)
445
+ @request.set_REQUEST_URI(url.rewrite(options))
438
446
  end
439
447
  end
440
448
 
441
449
  def html_document
442
- @html_document ||= HTML::Document.new(@response.body)
450
+ xml = @response.content_type =~ /xml$/
451
+ @html_document ||= HTML::Document.new(@response.body, false, xml)
443
452
  end
444
453
 
445
454
  def find_tag(conditions)
@@ -451,16 +460,20 @@ module ActionController #:nodoc:
451
460
  end
452
461
 
453
462
  def method_missing(selector, *args)
454
- return @controller.send(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
463
+ return @controller.send!(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
455
464
  return super
456
465
  end
457
466
 
458
467
  # Shortcut for ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + path, type). Example:
459
468
  # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png')
460
- def fixture_file_upload(path, mime_type = nil)
469
+ #
470
+ # To upload binary files on Windows, pass :binary as the last parameter. This will not affect other platforms.
471
+ # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png', :binary)
472
+ def fixture_file_upload(path, mime_type = nil, binary = false)
461
473
  ActionController::TestUploadedFile.new(
462
474
  Test::Unit::TestCase.respond_to?(:fixture_path) ? Test::Unit::TestCase.fixture_path + path : path,
463
- mime_type
475
+ mime_type,
476
+ binary
464
477
  )
465
478
  end
466
479
 
@@ -483,15 +496,15 @@ module ActionController #:nodoc:
483
496
  #
484
497
  def with_routing
485
498
  real_routes = ActionController::Routing::Routes
486
- ActionController::Routing.send :remove_const, :Routes
499
+ ActionController::Routing.module_eval { remove_const :Routes }
487
500
 
488
501
  temporary_routes = ActionController::Routing::RouteSet.new
489
- ActionController::Routing.send :const_set, :Routes, temporary_routes
490
-
502
+ ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
503
+
491
504
  yield temporary_routes
492
505
  ensure
493
506
  if ActionController::Routing.const_defined? :Routes
494
- ActionController::Routing.send(:remove_const, :Routes)
507
+ ActionController::Routing.module_eval { remove_const :Routes }
495
508
  end
496
509
  ActionController::Routing.const_set(:Routes, real_routes) if real_routes
497
510
  end
@@ -1,5 +1,4 @@
1
- module ActionController
2
-
1
+ module ActionController
3
2
  # Write URLs from arbitrary places in your codebase, such as your mailers.
4
3
  #
5
4
  # Example:
@@ -15,59 +14,71 @@ module ActionController
15
14
  #
16
15
  # In addition to providing +url_for+, named routes are also accessible after
17
16
  # including UrlWriter.
18
- #
19
17
  module UrlWriter
20
-
21
18
  # The default options for urls written by this writer. Typically a :host pair
22
19
  # is provided.
23
20
  mattr_accessor :default_url_options
24
21
  self.default_url_options = {}
25
22
 
26
23
  def self.included(base) #:nodoc:
27
- ActionController::Routing::Routes.named_routes.install base
24
+ ActionController::Routing::Routes.install_helpers base
28
25
  base.mattr_accessor :default_url_options
29
26
  base.default_url_options ||= default_url_options
30
27
  end
31
28
 
32
- # Generate a url with the provided options. The following special options may
33
- # effect the constructed url:
29
+ # Generate a url based on the options provided, default_url_options and the
30
+ # routes defined in routes.rb. The following options are supported:
31
+ #
32
+ # * <tt>:only_path</tt> If true, the relative url is returned. Defaults to false.
33
+ # * <tt>:protocol</tt> The protocol to connect to. Defaults to 'http'.
34
+ # * <tt>:host</tt> Specifies the host the link should be targetted at. If <tt>:only_path</tt> is false, this option must be
35
+ # provided either explicitly, or via default_url_options.
36
+ # * <tt>:port</tt> Optionally specify the port to connect to.
37
+ # * <tt>:anchor</tt> An anchor name to be appended to the path.
38
+ #
39
+ # Any other key(:controller, :action, etc...) given to <tt>url_for</tt> is forwarded to the Routes module.
34
40
  #
35
- # * :host Specifies the host the link should be targetted at. This option
36
- # must be provided either explicitly, or via default_url_options.
37
- # * :protocol The protocol to connect to. Defaults to 'http'
38
- # * :port Optionally specify the port to connect to.
41
+ # Examples:
42
+ #
43
+ # url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :port=>'8080' # => 'http://somehost.org:8080/tasks/testing'
44
+ # url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :anchor => 'ok', :only_path => true # => '/tasks/testing#ok'
45
+ # url_for :controller => 'tasks', :action => 'testing', :host=>'somehost.org', :number => '33' # => 'http://somehost.org/tasks/testing?number=33'
39
46
  #
40
47
  def url_for(options)
41
48
  options = self.class.default_url_options.merge(options)
42
49
 
43
50
  url = ''
51
+
44
52
  unless options.delete :only_path
45
53
  url << (options.delete(:protocol) || 'http')
46
- url << '://'
54
+ url << '://' unless url.match("://") #dont add separator if its already been specified in :protocol
47
55
 
48
56
  raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless options[:host]
57
+
49
58
  url << options.delete(:host)
50
59
  url << ":#{options.delete(:port)}" if options.key?(:port)
51
60
  else
52
61
  # Delete the unused options to prevent their appearance in the query string
53
62
  [:protocol, :host, :port].each { |k| options.delete k }
54
63
  end
55
- anchor = "##{options.delete(:anchor)}" if options.key?(:anchor)
64
+
65
+ anchor = "##{CGI.escape options.delete(:anchor).to_param.to_s}" if options.key?(:anchor)
56
66
  url << Routing::Routes.generate(options, {})
57
- return "#{url}#{anchor}"
58
- end
59
-
67
+ url << anchor if anchor
68
+
69
+ return url
70
+ end
60
71
  end
61
72
 
62
73
  # Rewrites URLs for Base.redirect_to and Base.url_for in the controller.
63
74
  class UrlRewriter #:nodoc:
64
- RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :trailing_slash, :skip_relative_url_root]
75
+ RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash, :skip_relative_url_root]
65
76
  def initialize(request, parameters)
66
77
  @request, @parameters = request, parameters
67
78
  end
68
79
 
69
80
  def rewrite(options = {})
70
- rewrite_url(rewrite_path(options), options)
81
+ rewrite_url(options)
71
82
  end
72
83
 
73
84
  def to_str
@@ -78,16 +89,20 @@ module ActionController
78
89
 
79
90
  private
80
91
  # Given a path and options, returns a rewritten URL string
81
- def rewrite_url(path, options)
92
+ def rewrite_url(options)
82
93
  rewritten_url = ""
94
+
83
95
  unless options[:only_path]
84
96
  rewritten_url << (options[:protocol] || @request.protocol)
97
+ rewritten_url << "://" unless rewritten_url.match("://")
98
+ rewritten_url << rewrite_authentication(options)
85
99
  rewritten_url << (options[:host] || @request.host_with_port)
100
+ rewritten_url << ":#{options.delete(:port)}" if options.key?(:port)
86
101
  end
87
102
 
103
+ path = rewrite_path(options)
88
104
  rewritten_url << @request.relative_url_root.to_s unless options[:skip_relative_url_root]
89
- rewritten_url << path
90
- rewritten_url << '/' if options[:trailing_slash]
105
+ rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
91
106
  rewritten_url << "##{options[:anchor]}" if options[:anchor]
92
107
 
93
108
  rewritten_url
@@ -97,15 +112,24 @@ module ActionController
97
112
  def rewrite_path(options)
98
113
  options = options.symbolize_keys
99
114
  options.update(options[:params].symbolize_keys) if options[:params]
115
+
100
116
  if (overwrite = options.delete(:overwrite_params))
101
117
  options.update(@parameters.symbolize_keys)
102
- options.update(overwrite)
118
+ options.update(overwrite.symbolize_keys)
103
119
  end
104
- RESERVED_OPTIONS.each {|k| options.delete k}
120
+
121
+ RESERVED_OPTIONS.each { |k| options.delete(k) }
105
122
 
106
123
  # Generates the query string, too
107
124
  Routing::Routes.generate(options, @request.symbolized_path_parameters)
108
125
  end
126
+
127
+ def rewrite_authentication(options)
128
+ if options[:user] && options[:password]
129
+ "#{CGI.escape(options.delete(:user))}:#{CGI.escape(options.delete(:password))}@"
130
+ else
131
+ ""
132
+ end
133
+ end
109
134
  end
110
-
111
135
  end