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 @@
1
+ <%= greeting %>: <%= hash_greeting[:first_name] %>
@@ -0,0 +1,2 @@
1
+ <%= hash_object[:first_name] %>
2
+ <%= object[:first_name].reverse %>
@@ -0,0 +1,3 @@
1
+ Before (<%= name %>)
2
+ <%= yield %>
3
+ After
@@ -0,0 +1 @@
1
+ invalid
@@ -0,0 +1 @@
1
+ partial html
@@ -0,0 +1 @@
1
+ partial js
@@ -0,0 +1 @@
1
+ Inside from partial (<%= name %>)
@@ -0,0 +1 @@
1
+ <%= render(:layout => "layout_for_partial", :partial => "partial_for_use_in_layout", :locals => { :name => "David" }) %>
@@ -0,0 +1,3 @@
1
+ <% content_for :title, "Putting stuff "
2
+ content_for :title, "in the title!" %>
3
+ Great stuff!
@@ -0,0 +1,2 @@
1
+ <% content_for :title, "Putting stuff in the title!" %>
2
+ Great stuff!
@@ -0,0 +1 @@
1
+ formatted html erb
@@ -0,0 +1 @@
1
+ xml.test 'failed'
@@ -0,0 +1 @@
1
+ <test>passed formatted html erb</test>
@@ -0,0 +1 @@
1
+ <test>passed formatted xml erb</test>
@@ -0,0 +1 @@
1
+ <%= @test_unchanged = 'goodbye' %><%= render :partial => 'customer', :collection => @customers %><%= @test_unchanged %>
@@ -0,0 +1 @@
1
+ <% render(:layout => "layout_for_partial", :locals => { :name => "David" }) do %>Inside from block<% end %>
@@ -1,3 +1,3 @@
1
1
  class Topic < ActiveRecord::Base
2
- has_many :replies, :include => [:user], :dependent => :destroy
2
+ has_many :replies, :dependent => :destroy
3
3
  end
@@ -1,11 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
2
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
3
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
4
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
5
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
6
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper'
7
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
8
- # require File.dirname(__FILE__) + '/../../lib/action_view/helpers/active_record_helper'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
9
2
 
10
3
  class ActiveRecordHelperTest < Test::Unit::TestCase
11
4
  include ActionView::Helpers::FormHelper
@@ -35,7 +28,16 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
35
28
  @post = Post.new
36
29
  def @post.errors
37
30
  Class.new {
38
- def on(field) field == "author_name" || field == "body" end
31
+ def on(field)
32
+ case field.to_s
33
+ when "author_name"
34
+ "can't be empty"
35
+ when "body"
36
+ true
37
+ else
38
+ false
39
+ end
40
+ end
39
41
  def empty?() false end
40
42
  def count() 1 end
41
43
  def full_messages() [ "Author name can't be empty" ] end
@@ -59,7 +61,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
59
61
  @post.secret = 1
60
62
  @post.written_on = Date.new(2004, 6, 15)
61
63
  end
62
-
64
+
63
65
  def setup_user
64
66
  @user = User.new
65
67
  def @user.errors
@@ -89,8 +91,10 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
89
91
  setup_post
90
92
  setup_user
91
93
 
94
+ @response = ActionController::TestResponse.new
95
+
92
96
  @controller = Object.new
93
- def @controller.url_for(options, *parameters_for_method_reference)
97
+ def @controller.url_for(options)
94
98
  options = options.symbolize_keys
95
99
 
96
100
  [options[:action], options[:id].to_param].compact.join('/')
@@ -102,7 +106,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
102
106
  %(<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />), input("post", "title")
103
107
  )
104
108
  end
105
-
109
+
106
110
  def test_text_area_with_errors
107
111
  assert_dom_equal(
108
112
  %(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
@@ -116,7 +120,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
116
120
  text_field("post", "author_name")
117
121
  )
118
122
  end
119
-
123
+
120
124
  def test_form_with_string
121
125
  assert_dom_equal(
122
126
  %(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
@@ -136,7 +140,14 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
136
140
  form("post")
137
141
  )
138
142
  end
139
-
143
+
144
+ def test_form_with_action_option
145
+ @response.body = form("post", :action => "sign")
146
+ assert_select "form[action=sign]" do |form|
147
+ assert_select "input[type=submit][value=Sign]"
148
+ end
149
+ end
150
+
140
151
  def test_form_with_date
141
152
  silence_warnings do
142
153
  def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
@@ -159,26 +170,35 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
159
170
  form("post")
160
171
  )
161
172
  end
162
-
173
+
163
174
  def test_error_for_block
164
175
  assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
165
176
  assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
166
177
  assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
167
178
  assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
168
179
  end
169
-
180
+
170
181
  def test_error_messages_for_handles_nil
171
182
  assert_equal "", error_messages_for("notthere")
172
183
  end
173
-
184
+
174
185
  def test_error_message_on_handles_nil
175
186
  assert_equal "", error_message_on("notthere", "notthere")
176
187
  end
177
-
188
+
178
189
  def test_error_message_on
179
- assert error_message_on(:post, :author_name)
190
+ assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name)
191
+ end
192
+
193
+ def test_error_message_on_no_instance_variable
194
+ other_post = @post
195
+ assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name)
180
196
  end
181
197
 
198
+ def test_error_message_on_should_use_options
199
+ assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, "before", "after", "differentError")
200
+ end
201
+
182
202
  def test_error_messages_for_many_objects
183
203
  assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
184
204
 
@@ -193,8 +213,35 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
193
213
 
194
214
  # any default works too
195
215
  assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")
196
- end
197
216
 
217
+ # should space object name
218
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon")
219
+
220
+ # hide header and explanation messages with nil or empty string
221
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => nil, :message => "")
222
+
223
+ # override header and explanation messages
224
+ header_message = "Yikes! Some errors"
225
+ message = "Please fix the following fields and resubmit:"
226
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message)
227
+ end
228
+
229
+ def test_error_messages_for_non_instance_variable
230
+ actual_user = @user
231
+ actual_post = @post
232
+ @user = nil
233
+ @post = nil
234
+
235
+ #explicitly set object
236
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post)
237
+
238
+ #multiple objects
239
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post])
240
+
241
+ #nil object
242
+ assert_equal '', error_messages_for('user', :object => nil)
243
+ end
244
+
198
245
  def test_form_with_string_multipart
199
246
  assert_dom_equal(
200
247
  %(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
2
 
3
3
  class AssetTagHelperTest < Test::Unit::TestCase
4
4
  include ActionView::Helpers::TagHelper
@@ -6,29 +6,46 @@ class AssetTagHelperTest < Test::Unit::TestCase
6
6
  include ActionView::Helpers::AssetTagHelper
7
7
 
8
8
  def setup
9
- @controller = Class.new do
9
+ silence_warnings do
10
+ ActionView::Helpers::AssetTagHelper.send(
11
+ :const_set,
12
+ :JAVASCRIPTS_DIR,
13
+ File.dirname(__FILE__) + "/../fixtures/public/javascripts"
14
+ )
15
+
16
+ ActionView::Helpers::AssetTagHelper.send(
17
+ :const_set,
18
+ :STYLESHEETS_DIR,
19
+ File.dirname(__FILE__) + "/../fixtures/public/stylesheets"
20
+ )
21
+
22
+ ActionView::Helpers::AssetTagHelper.send(
23
+ :const_set,
24
+ :ASSETS_DIR,
25
+ File.dirname(__FILE__) + "/../fixtures/public"
26
+ )
27
+ end
10
28
 
29
+ @controller = Class.new do
11
30
  attr_accessor :request
12
-
13
- def url_for(options, *parameters_for_method_reference)
14
- "http://www.example.com"
15
- end
16
-
31
+ def url_for(*args) "http://www.example.com" end
17
32
  end.new
18
-
19
- @request = Class.new do
20
- def relative_url_root
21
- ""
22
- end
33
+
34
+ @request = Class.new do
35
+ def relative_url_root() "" end
36
+ def protocol() 'http://' end
23
37
  end.new
24
38
 
25
39
  @controller.request = @request
26
-
40
+
27
41
  ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
42
+
43
+ ActionView::Base.computed_public_paths.clear
28
44
  end
29
45
 
30
46
  def teardown
31
- Object.send(:remove_const, :RAILS_ROOT) if defined?(RAILS_ROOT)
47
+ ActionController::Base.perform_caching = false
48
+ ActionController::Base.asset_host = nil
32
49
  ENV["RAILS_ASSET_ID"] = nil
33
50
  end
34
51
 
@@ -36,6 +53,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
36
53
  %(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
37
54
  %(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
38
55
  %(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
56
+ %(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />),
39
57
  %(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
40
58
  %(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
41
59
  %(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
@@ -52,14 +70,21 @@ class AssetTagHelperTest < Test::Unit::TestCase
52
70
  %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
53
71
  }
54
72
 
73
+ PathToJavascriptToTag = {
74
+ %(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js),
75
+ %(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
76
+ %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js)
77
+ }
78
+
55
79
  JavascriptIncludeToTag = {
56
80
  %(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
57
81
  %(javascript_include_tag("xmlhr.js")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
58
82
  %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
59
83
  %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
60
- %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>),
61
- %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>),
62
- %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>)
84
+ %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
85
+ %(javascript_include_tag(:all)) => %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
86
+ %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
87
+ %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
63
88
  }
64
89
 
65
90
  StylePathToTag = {
@@ -69,22 +94,39 @@ class AssetTagHelperTest < Test::Unit::TestCase
69
94
  %(stylesheet_path('/dir/file.rcss')) => %(/dir/file.rcss)
70
95
  }
71
96
 
97
+ PathToStyleToTag = {
98
+ %(path_to_stylesheet("style")) => %(/stylesheets/style.css),
99
+ %(path_to_stylesheet("style.css")) => %(/stylesheets/style.css),
100
+ %(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css),
101
+ %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss)
102
+ }
103
+
72
104
  StyleLinkToTag = {
73
- %(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
74
- %(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
75
- %(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="Stylesheet" type="text/css" />),
76
- %(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="Stylesheet" type="text/css" />),
77
- %(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />),
78
- %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />),
79
- %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="Stylesheet" type="text/css" />)
105
+ %(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
106
+ %(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
107
+ %(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
108
+ %(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
109
+ %(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />),
110
+ %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
111
+ %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />),
112
+ %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />),
113
+ %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
80
114
  }
81
115
 
82
116
  ImagePathToTag = {
83
- %(image_path("xml.png")) => %(/images/xml.png),
84
- %(image_path("dir/xml.png")) => %(/images/dir/xml.png),
117
+ %(image_path("xml")) => %(/images/xml),
118
+ %(image_path("xml.png")) => %(/images/xml.png),
119
+ %(image_path("dir/xml.png")) => %(/images/dir/xml.png),
85
120
  %(image_path("/dir/xml.png")) => %(/dir/xml.png)
86
121
  }
87
122
 
123
+ PathToImageToTag = {
124
+ %(path_to_image("xml")) => %(/images/xml),
125
+ %(path_to_image("xml.png")) => %(/images/xml.png),
126
+ %(path_to_image("dir/xml.png")) => %(/images/dir/xml.png),
127
+ %(path_to_image("/dir/xml.png")) => %(/dir/xml.png)
128
+ }
129
+
88
130
  ImageLinkToTag = {
89
131
  %(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
90
132
  %(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
@@ -93,11 +135,10 @@ class AssetTagHelperTest < Test::Unit::TestCase
93
135
  %(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />),
94
136
  %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />),
95
137
  %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />),
96
- %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />)
97
- }
98
-
99
- DeprecatedImagePathToTag = {
100
- %(image_path("xml")) => %(/images/xml.png)
138
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
139
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
140
+ %(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
141
+ %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />)
101
142
  }
102
143
 
103
144
 
@@ -109,26 +150,38 @@ class AssetTagHelperTest < Test::Unit::TestCase
109
150
  JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
110
151
  end
111
152
 
153
+ def test_path_to_javascript_alias_for_javascript_path
154
+ PathToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
155
+ end
156
+
112
157
  def test_javascript_include_tag
158
+ ENV["RAILS_ASSET_ID"] = ""
113
159
  JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
114
-
115
- Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
116
- ENV["RAILS_ASSET_ID"] = "1"
160
+
161
+ ActionView::Base.computed_public_paths.clear
162
+
163
+ ENV["RAILS_ASSET_ID"] = "1"
117
164
  assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>), javascript_include_tag(:defaults))
118
165
  end
119
-
166
+
120
167
  def test_register_javascript_include_default
168
+ ENV["RAILS_ASSET_ID"] = ""
121
169
  ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'slider'
122
- assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
170
+ assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
123
171
  ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2'
124
- assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
172
+ assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
125
173
  end
126
174
 
127
175
  def test_stylesheet_path
128
176
  StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
129
177
  end
130
178
 
179
+ def test_path_to_stylesheet_alias_for_stylesheet_path
180
+ PathToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
181
+ end
182
+
131
183
  def test_stylesheet_link_tag
184
+ ENV["RAILS_ASSET_ID"] = ""
132
185
  StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
133
186
  end
134
187
 
@@ -136,41 +189,30 @@ class AssetTagHelperTest < Test::Unit::TestCase
136
189
  ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
137
190
  end
138
191
 
192
+ def test_path_to_image_alias_for_image_path
193
+ PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
194
+ end
195
+
139
196
  def test_image_tag
140
197
  ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
141
198
  end
142
199
 
143
- def test_should_deprecate_image_filename_with_no_extension
144
- DeprecatedImagePathToTag.each do |method, tag|
145
- assert_deprecated("image_path") { assert_dom_equal(tag, eval(method)) }
146
- end
147
- end
148
-
149
200
  def test_timebased_asset_id
150
- Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
151
201
  expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
152
202
  assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
153
203
  end
154
204
 
155
205
  def test_should_skip_asset_id_on_complete_url
156
- Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
157
206
  assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
158
207
  end
159
208
 
160
209
  def test_should_use_preset_asset_id
161
- Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
162
210
  ENV["RAILS_ASSET_ID"] = "4500"
163
211
  assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
164
212
  end
165
213
 
166
214
  def test_preset_empty_asset_id
167
- Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
168
- # on windows, setting ENV["XXX"] to "" makes ENV["XXX"] return nil
169
- if RUBY_PLATFORM =~ /win32/
170
- ENV["RAILS_ASSET_ID"] = " "
171
- else
172
215
  ENV["RAILS_ASSET_ID"] = ""
173
- end
174
216
  assert_equal %(<img alt="Rails" src="/images/rails.png" />), image_tag("rails.png")
175
217
  end
176
218
 
@@ -180,6 +222,107 @@ class AssetTagHelperTest < Test::Unit::TestCase
180
222
  image_tag(source)
181
223
  assert_equal copy, source
182
224
  end
225
+
226
+
227
+ def test_caching_javascript_include_tag_when_caching_on
228
+ ENV["RAILS_ASSET_ID"] = ""
229
+ ActionController::Base.asset_host = 'http://a%d.example.com'
230
+ ActionController::Base.perform_caching = true
231
+
232
+ assert_dom_equal(
233
+ %(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>),
234
+ javascript_include_tag(:all, :cache => true)
235
+ )
236
+
237
+ assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
238
+
239
+ assert_dom_equal(
240
+ %(<script src="http://a2.example.com/javascripts/money.js" type="text/javascript"></script>),
241
+ javascript_include_tag(:all, :cache => "money")
242
+ )
243
+
244
+ assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
245
+
246
+ ensure
247
+ File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
248
+ File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
249
+ end
250
+
251
+ def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
252
+ ENV["RAILS_ASSET_ID"] = ""
253
+ ActionController::Base.asset_host = 'http://a%d.example.com'
254
+ ActionController::Base.perform_caching = true
255
+
256
+ assert_dom_equal(
257
+ %(<script src="http://a3.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
258
+ javascript_include_tag(:all, :cache => "cache/money")
259
+ )
260
+
261
+ assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
262
+ ensure
263
+ File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
264
+ end
265
+
266
+ def test_caching_javascript_include_tag_when_caching_off
267
+ ENV["RAILS_ASSET_ID"] = ""
268
+ ActionController::Base.perform_caching = false
269
+
270
+ assert_dom_equal(
271
+ %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
272
+ javascript_include_tag(:all, :cache => true)
273
+ )
274
+
275
+ assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
276
+
277
+ assert_dom_equal(
278
+ %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
279
+ javascript_include_tag(:all, :cache => "money")
280
+ )
281
+
282
+ assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
283
+ end
284
+
285
+ def test_caching_stylesheet_link_tag_when_caching_on
286
+ ENV["RAILS_ASSET_ID"] = ""
287
+ ActionController::Base.asset_host = 'http://a%d.example.com'
288
+ ActionController::Base.perform_caching = true
289
+
290
+ assert_dom_equal(
291
+ %(<link href="http://a3.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
292
+ stylesheet_link_tag(:all, :cache => true)
293
+ )
294
+
295
+ assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
296
+
297
+ assert_dom_equal(
298
+ %(<link href="http://a3.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
299
+ stylesheet_link_tag(:all, :cache => "money")
300
+ )
301
+
302
+ assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
303
+ ensure
304
+ File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
305
+ File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
306
+ end
307
+
308
+ def test_caching_stylesheet_include_tag_when_caching_off
309
+ ENV["RAILS_ASSET_ID"] = ""
310
+ ActionController::Base.perform_caching = false
311
+
312
+ assert_dom_equal(
313
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
314
+ stylesheet_link_tag(:all, :cache => true)
315
+ )
316
+
317
+ assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
318
+
319
+ assert_dom_equal(
320
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
321
+ stylesheet_link_tag(:all, :cache => "money")
322
+ )
323
+
324
+ assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
325
+ end
183
326
  end
184
327
 
185
328
  class AssetTagHelperNonVhostTest < Test::Unit::TestCase
@@ -191,7 +334,7 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
191
334
  @controller = Class.new do
192
335
  attr_accessor :request
193
336
 
194
- def url_for(options, *parameters_for_method_reference)
337
+ def url_for(options)
195
338
  "http://www.example.com/collaboration/hieraki"
196
339
  end
197
340
  end.new
@@ -200,6 +343,10 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
200
343
  def relative_url_root
201
344
  "/collaboration/hieraki"
202
345
  end
346
+
347
+ def protocol
348
+ 'gopher://'
349
+ end
203
350
  end.new
204
351
 
205
352
  @controller.request = @request
@@ -230,8 +377,29 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
230
377
 
231
378
  def test_should_ignore_asset_host_on_complete_url
232
379
  ActionController::Base.asset_host = "http://assets.example.com"
233
- assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
380
+ assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
234
381
  ensure
235
382
  ActionController::Base.asset_host = ""
236
383
  end
384
+
385
+ def test_should_wildcard_asset_host_between_zero_and_four
386
+ ActionController::Base.asset_host = 'http://a%d.example.com'
387
+ assert_match %r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')
388
+ ensure
389
+ ActionController::Base.asset_host = nil
390
+ end
391
+
392
+ def test_asset_host_without_protocol_should_use_request_protocol
393
+ ActionController::Base.asset_host = 'a.example.com'
394
+ assert_equal 'gopher://a.example.com/collaboration/hieraki/images/xml.png', image_path('xml.png')
395
+ ensure
396
+ ActionController::Base.asset_host = nil
397
+ end
398
+
399
+ def test_asset_host_without_protocol_should_use_request_protocol_even_if_path_present
400
+ ActionController::Base.asset_host = 'a.example.com/files/go/here'
401
+ assert_equal 'gopher://a.example.com/files/go/here/collaboration/hieraki/images/xml.png', image_path('xml.png')
402
+ ensure
403
+ ActionController::Base.asset_host = nil
404
+ end
237
405
  end