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
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
2
 
3
3
  class FormTagHelperTest < Test::Unit::TestCase
4
4
  include ActionView::Helpers::UrlHelper
@@ -9,7 +9,7 @@ class FormTagHelperTest < Test::Unit::TestCase
9
9
 
10
10
  def setup
11
11
  @controller = Class.new do
12
- def url_for(options, *parameters_for_method_reference)
12
+ def url_for(options)
13
13
  "http://www.example.com"
14
14
  end
15
15
  end
@@ -34,17 +34,23 @@ class FormTagHelperTest < Test::Unit::TestCase
34
34
  assert_dom_equal expected, actual
35
35
  end
36
36
 
37
- def test_form_tag_with_method
37
+ def test_form_tag_with_method_put
38
38
  actual = form_tag({}, { :method => :put })
39
39
  expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>)
40
40
  assert_dom_equal expected, actual
41
41
  end
42
+
43
+ def test_form_tag_with_method_delete
44
+ actual = form_tag({}, { :method => :delete })
45
+ expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="delete" /></div>)
46
+ assert_dom_equal expected, actual
47
+ end
42
48
 
43
49
  def test_form_tag_with_block
44
50
  _erbout = ''
45
51
  form_tag("http://example.com") { _erbout.concat "Hello world!" }
46
52
 
47
- expected = %(<form action="http://www.example.com" method="post">Hello world!</form>)
53
+ expected = %(<form action="http://example.com" method="post">Hello world!</form>)
48
54
  assert_dom_equal expected, _erbout
49
55
  end
50
56
 
@@ -52,7 +58,7 @@ class FormTagHelperTest < Test::Unit::TestCase
52
58
  _erbout = ''
53
59
  form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" }
54
60
 
55
- expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
61
+ expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
56
62
  assert_dom_equal expected, _erbout
57
63
  end
58
64
 
@@ -62,6 +68,14 @@ class FormTagHelperTest < Test::Unit::TestCase
62
68
  assert_dom_equal expected, actual
63
69
  end
64
70
 
71
+ def test_file_field_tag
72
+ assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" />", file_field_tag("picsplz")
73
+ end
74
+
75
+ def test_file_field_tag_with_options
76
+ assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" class=\"pix\"/>", file_field_tag("picsplz", :class => "pix")
77
+ end
78
+
65
79
  def test_password_field_tag
66
80
  actual = password_field_tag
67
81
  expected = %(<input id="password" name="password" type="password" />)
@@ -85,6 +99,9 @@ class FormTagHelperTest < Test::Unit::TestCase
85
99
  expected = %(<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />)
86
100
  assert_dom_equal expected, actual
87
101
 
102
+ actual = radio_button_tag("person[gender]", "m")
103
+ expected = %(<input id="person_gender_m" name="person[gender]" type="radio" value="m" />)
104
+ assert_dom_equal expected, actual
88
105
  end
89
106
 
90
107
  def test_select_tag
@@ -92,6 +109,18 @@ class FormTagHelperTest < Test::Unit::TestCase
92
109
  expected = %(<select id="people" name="people"><option>david</option></select>)
93
110
  assert_dom_equal expected, actual
94
111
  end
112
+
113
+ def test_select_tag_with_multiple
114
+ actual = select_tag "colors", "<option>Red</option><option>Blue</option><option>Green</option>", :multiple => :true
115
+ expected = %(<select id="colors" multiple="multiple" name="colors"><option>Red</option><option>Blue</option><option>Green</option></select>)
116
+ assert_dom_equal expected, actual
117
+ end
118
+
119
+ def test_select_tag_disabled
120
+ actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>", :disabled => :true
121
+ expected = %(<select id="places" disabled="disabled" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>)
122
+ assert_dom_equal expected, actual
123
+ end
95
124
 
96
125
  def test_text_area_tag_size_string
97
126
  actual = text_area_tag "body", "hello world", "size" => "20x40"
@@ -105,6 +134,12 @@ class FormTagHelperTest < Test::Unit::TestCase
105
134
  assert_dom_equal expected, actual
106
135
  end
107
136
 
137
+ def test_text_area_tag_should_disregard_size_if_its_given_as_an_integer
138
+ actual = text_area_tag "body", "hello world", :size => 20
139
+ expected = %(<textarea id="body" name="body">hello world</textarea>)
140
+ assert_dom_equal expected, actual
141
+ end
142
+
108
143
  def test_text_field_tag
109
144
  actual = text_field_tag "title", "Hello!"
110
145
  expected = %(<input id="title" name="title" type="text" value="Hello!" />)
@@ -116,6 +151,42 @@ class FormTagHelperTest < Test::Unit::TestCase
116
151
  expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
117
152
  assert_dom_equal expected, actual
118
153
  end
154
+
155
+ def test_text_field_tag_size_symbol
156
+ actual = text_field_tag "title", "Hello!", :size => 75
157
+ expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
158
+ assert_dom_equal expected, actual
159
+ end
160
+
161
+ def test_text_field_tag_size_string
162
+ actual = text_field_tag "title", "Hello!", "size" => "75"
163
+ expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
164
+ assert_dom_equal expected, actual
165
+ end
166
+
167
+ def test_text_field_tag_maxlength_symbol
168
+ actual = text_field_tag "title", "Hello!", :maxlength => 75
169
+ expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
170
+ assert_dom_equal expected, actual
171
+ end
172
+
173
+ def test_text_field_tag_maxlength_string
174
+ actual = text_field_tag "title", "Hello!", "maxlength" => "75"
175
+ expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
176
+ assert_dom_equal expected, actual
177
+ end
178
+
179
+ def test_text_field_disabled
180
+ actual = text_field_tag "title", "Hello!", :disabled => :true
181
+ expected = %(<input id="title" name="title" disabled="disabled" type="text" value="Hello!" />)
182
+ assert_dom_equal expected, actual
183
+ end
184
+
185
+ def test_text_field_tag_with_multiple_options
186
+ actual = text_field_tag "title", "Hello!", :size => 70, :maxlength => 80
187
+ expected = %(<input id="title" name="title" size="70" maxlength="80" type="text" value="Hello!" />)
188
+ assert_dom_equal expected, actual
189
+ end
119
190
 
120
191
  def test_boolean_optios
121
192
  assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
@@ -132,7 +203,7 @@ class FormTagHelperTest < Test::Unit::TestCase
132
203
 
133
204
  def test_submit_tag
134
205
  assert_dom_equal(
135
- %(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';this.form.submit();alert('hello!')" />),
206
+ %(<input name='commit' type='submit' value='Save' onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result" />),
136
207
  submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
137
208
  )
138
209
  end
@@ -140,33 +211,28 @@ class FormTagHelperTest < Test::Unit::TestCase
140
211
  def test_pass
141
212
  assert_equal 1, 1
142
213
  end
143
- end
144
214
 
145
- class DeprecatedFormTagHelperTest < Test::Unit::TestCase
146
- include ActionView::Helpers::UrlHelper
147
- include ActionView::Helpers::TagHelper
148
- include ActionView::Helpers::FormTagHelper
149
- include ActionView::Helpers::TextHelper
150
- include ActionView::Helpers::CaptureHelper
215
+ def test_field_set_tag
216
+ _erbout = ''
217
+ field_set_tag("Your details") { _erbout.concat "Hello world!" }
151
218
 
152
- def setup
153
- @controller = Class.new do
154
- def url_for(options, *parameters_for_method_reference)
155
- "http://www.example.com"
156
- end
157
- end
158
- @controller = @controller.new
159
- end
219
+ expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>)
220
+ assert_dom_equal expected, _erbout
160
221
 
161
- def test_start_form_tag_deprecation
162
- assert_deprecated /start_form_tag/ do
163
- start_form_tag
164
- end
222
+ _erbout = ''
223
+ field_set_tag { _erbout.concat "Hello world!" }
224
+
225
+ expected = %(<fieldset>Hello world!</fieldset>)
226
+ assert_dom_equal expected, _erbout
227
+
228
+ _erbout = ''
229
+ field_set_tag('') { _erbout.concat "Hello world!" }
230
+
231
+ expected = %(<fieldset>Hello world!</fieldset>)
232
+ assert_dom_equal expected, _erbout
165
233
  end
166
-
167
- def test_end_form_tag_deprecation
168
- assert_deprecated /end_form_tag/ do
169
- end_form_tag
170
- end
234
+
235
+ def protect_against_forgery?
236
+ false
171
237
  end
172
238
  end
@@ -1,34 +1,36 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
2
 
3
3
  class JavaScriptHelperTest < Test::Unit::TestCase
4
4
  include ActionView::Helpers::JavaScriptHelper
5
-
5
+
6
6
  include ActionView::Helpers::UrlHelper
7
7
  include ActionView::Helpers::TagHelper
8
8
  include ActionView::Helpers::TextHelper
9
9
  include ActionView::Helpers::FormHelper
10
10
  include ActionView::Helpers::CaptureHelper
11
-
11
+
12
12
  def test_define_javascript_functions
13
13
  # check if prototype.js is included first
14
14
  assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
15
-
15
+
16
16
  # check that scriptaculous.js is not in here, only needed if loaded remotely
17
17
  assert_nil define_javascript_functions.split("\n")[1].match(/var Scriptaculous = \{/)
18
18
  end
19
19
 
20
20
  def test_escape_javascript
21
+ assert_equal '', escape_javascript(nil)
21
22
  assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
22
23
  assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) )
24
+ assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
23
25
  end
24
-
26
+
25
27
  def test_link_to_function
26
- assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
28
+ assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
27
29
  link_to_function("Greeting", "alert('Hello world!')")
28
30
  end
29
-
31
+
30
32
  def test_link_to_function_with_existing_onclick
31
- assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
33
+ assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
32
34
  link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
33
35
  end
34
36
 
@@ -36,18 +38,28 @@ class JavaScriptHelperTest < Test::Unit::TestCase
36
38
  html = link_to_function( "Greet me!" ) do |page|
37
39
  page.replace_html 'header', "<h1>Greetings</h1>"
38
40
  end
39
- assert_dom_equal %q(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\074h1\076Greetings\074/h1\076&quot;);; return false;">Greet me!</a>), html
41
+ assert_dom_equal %(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);; return false;">Greet me!</a>), html
40
42
  end
41
43
 
42
44
  def test_link_to_function_with_rjs_block_and_options
43
45
  html = link_to_function( "Greet me!", :class => "updater" ) do |page|
44
46
  page.replace_html 'header', "<h1>Greetings</h1>"
45
47
  end
46
- assert_dom_equal %q(<a href="#" class="updater" onclick="Element.update(&quot;header&quot;, &quot;\074h1\076Greetings\074/h1\076&quot;);; return false;">Greet me!</a>), html
48
+ assert_dom_equal %(<a href="#" class="updater" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);; return false;">Greet me!</a>), html
49
+ end
50
+
51
+ def test_link_to_function_with_href
52
+ assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
53
+ link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
54
+ end
55
+
56
+ def test_link_to_function_with_href
57
+ assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
58
+ link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
47
59
  end
48
60
 
49
61
  def test_button_to_function
50
- assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
62
+ assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
51
63
  button_to_function("Greeting", "alert('Hello world!')")
52
64
  end
53
65
 
@@ -55,13 +67,49 @@ class JavaScriptHelperTest < Test::Unit::TestCase
55
67
  html = button_to_function( "Greet me!" ) do |page|
56
68
  page.replace_html 'header', "<h1>Greetings</h1>"
57
69
  end
58
- assert_dom_equal %q(<input type="button" onclick="Element.update(&quot;header&quot;, &quot;\074h1\076Greetings\074/h1\076&quot;);;" value="Greet me!" />), html
70
+ assert_dom_equal %(<input type="button" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);;" value="Greet me!" />), html
59
71
  end
60
72
 
61
73
  def test_button_to_function_with_rjs_block_and_options
62
74
  html = button_to_function( "Greet me!", :class => "greeter" ) do |page|
63
75
  page.replace_html 'header', "<h1>Greetings</h1>"
64
76
  end
65
- assert_dom_equal %q(<input type="button" class="greeter" onclick="Element.update(&quot;header&quot;, &quot;\074h1\076Greetings\074/h1\076&quot;);;" value="Greet me!" />), html
77
+ assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\/h1\\u003E&quot;);;" value="Greet me!" />), html
78
+ end
79
+
80
+ def test_button_to_function_with_onclick
81
+ assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />",
82
+ button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')")
83
+ end
84
+
85
+ def test_button_to_function_without_function
86
+ assert_dom_equal "<input onclick=\";\" type=\"button\" value=\"Greeting\" />",
87
+ button_to_function("Greeting")
88
+ end
89
+
90
+ def test_javascript_tag
91
+ assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
92
+ javascript_tag("alert('hello')")
93
+ end
94
+
95
+ def test_javascript_tag_with_options
96
+ assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
97
+ javascript_tag("alert('hello')", :id => "the_js_tag")
98
+ end
99
+
100
+ def test_javascript_tag_with_block
101
+ _erbout = ''
102
+ javascript_tag { _erbout.concat "alert('hello')" }
103
+ assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", _erbout
104
+ end
105
+
106
+ def test_javascript_tag_with_block_and_options
107
+ _erbout = ''
108
+ javascript_tag(:id => "the_js_tag") { _erbout.concat "alert('hello')" }
109
+ assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", _erbout
110
+ end
111
+
112
+ def test_javascript_cdata_section
113
+ assert_dom_equal "\n//<![CDATA[\nalert('hello')\n//]]>\n", javascript_cdata_section("alert('hello')")
66
114
  end
67
115
  end
@@ -1,5 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
2
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/number_helper'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
3
2
 
4
3
  class NumberHelperTest < Test::Unit::TestCase
5
4
  include ActionView::Helpers::NumberHelper
@@ -22,7 +21,7 @@ class NumberHelperTest < Test::Unit::TestCase
22
21
  def test_number_to_currency
23
22
  assert_equal("$1,234,567,890.50", number_to_currency(1234567890.50))
24
23
  assert_equal("$1,234,567,890.51", number_to_currency(1234567890.506))
25
- assert_equal("$1,234,567,891", number_to_currency(1234567890.51, {:precision => 0}))
24
+ assert_equal("$1,234,567,892", number_to_currency(1234567891.50, {:precision => 0}))
26
25
  assert_equal("$1,234,567,890.5", number_to_currency(1234567890.50, {:precision => 1}))
27
26
  assert_equal("&pound;1234567890,50", number_to_currency(1234567890.50, {:unit => "&pound;", :separator => ",", :delimiter => ""}))
28
27
  assert_equal("$1,234,567,890.50", number_to_currency("1234567890.50"))
@@ -53,16 +52,20 @@ class NumberHelperTest < Test::Unit::TestCase
53
52
  assert_equal("x", number_with_delimiter("x"))
54
53
  assert_nil number_with_delimiter(nil)
55
54
  end
56
-
55
+
57
56
  def test_number_with_precision
58
57
  assert_equal("111.235", number_with_precision(111.2346))
59
58
  assert_equal("111.23", number_with_precision(111.2346, 2))
60
59
  assert_equal("111.00", number_with_precision(111, 2))
61
60
  assert_equal("111.235", number_with_precision("111.2346"))
61
+ assert_equal("112", number_with_precision(111.50, 0))
62
+ assert_equal("1234567892", number_with_precision(1234567891.50, 0))
63
+
64
+ # Return non-numeric params unchanged.
62
65
  assert_equal("x", number_with_precision("x"))
63
66
  assert_nil number_with_precision(nil)
64
67
  end
65
-
68
+
66
69
  def test_number_to_human_size
67
70
  assert_equal '0 Bytes', number_to_human_size(0)
68
71
  assert_equal '1 Byte', number_to_human_size(1)
@@ -80,13 +83,11 @@ class NumberHelperTest < Test::Unit::TestCase
80
83
  assert_equal '1.18 MB', number_to_human_size(1234567, 2)
81
84
  assert_equal '3 Bytes', number_to_human_size(3.14159265, 4)
82
85
  assert_equal("123 Bytes", number_to_human_size("123"))
86
+ assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, 2)
87
+ assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4)
88
+ assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4)
89
+ assert_equal '1 Byte', number_to_human_size(1.1)
83
90
  assert_nil number_to_human_size('x')
84
91
  assert_nil number_to_human_size(nil)
85
92
  end
86
-
87
- def test_human_size_alias_is_deprecated
88
- assert_deprecated 'human_size' do
89
- assert_equal '0 Bytes', human_size(0)
90
- end
91
- end
92
93
  end
@@ -1,6 +1,34 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
+
3
+ Bunny = Struct.new(:Bunny, :id)
4
+
5
+ class Author
6
+ attr_reader :id
7
+ def save; @id = 1 end
8
+ def new_record?; @id.nil? end
9
+ def name
10
+ @id.nil? ? 'new author' : "author ##{@id}"
11
+ end
12
+ end
13
+
14
+ class Article
15
+ attr_reader :id
16
+ attr_reader :author_id
17
+ def save; @id = 1; @author_id = 1 end
18
+ def new_record?; @id.nil? end
19
+ def name
20
+ @id.nil? ? 'new article' : "article ##{@id}"
21
+ end
22
+ end
23
+
24
+ class Author::Nested < Author; end
25
+
2
26
 
3
27
  module BaseTest
28
+ def self.included(base)
29
+ base.send :attr_accessor, :template_format
30
+ end
31
+
4
32
  include ActionView::Helpers::JavaScriptHelper
5
33
  include ActionView::Helpers::PrototypeHelper
6
34
  include ActionView::Helpers::ScriptaculousHelper
@@ -11,11 +39,13 @@ module BaseTest
11
39
  include ActionView::Helpers::FormTagHelper
12
40
  include ActionView::Helpers::FormHelper
13
41
  include ActionView::Helpers::CaptureHelper
42
+ include ActionView::Helpers::RecordIdentificationHelper
43
+ include ActionController::PolymorphicRoutes
14
44
 
15
45
  def setup
16
46
  @template = nil
17
47
  @controller = Class.new do
18
- def url_for(options, *parameters_for_method_reference)
48
+ def url_for(options)
19
49
  if options.is_a?(String)
20
50
  options
21
51
  else
@@ -30,6 +60,15 @@ module BaseTest
30
60
  end
31
61
 
32
62
  protected
63
+
64
+ def request_forgery_protection_token
65
+ nil
66
+ end
67
+
68
+ def protect_against_forgery?
69
+ false
70
+ end
71
+
33
72
  def create_generator
34
73
  block = Proc.new { |*args| yield *args if block_given? }
35
74
  JavaScriptGenerator.new self, &block
@@ -39,17 +78,28 @@ end
39
78
  class PrototypeHelperTest < Test::Unit::TestCase
40
79
  include BaseTest
41
80
 
81
+ def setup
82
+ @record = @author = Author.new
83
+ @article = Article.new
84
+ super
85
+ end
86
+
42
87
  def test_link_to_remote
43
- assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outpost</a>),
44
- link_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" })
45
- assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
46
- link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
47
- assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
48
- link_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot" })
49
- assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
50
- link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot" })
51
- assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&amp;b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
52
- link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
88
+ assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outauthor</a>),
89
+ link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }}, { :class => "fine" })
90
+ assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
91
+ link_to_remote("Remote outauthor", :complete => "alert(request.responseText)", :url => { :action => "whatnot" })
92
+ assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
93
+ link_to_remote("Remote outauthor", :success => "alert(request.responseText)", :url => { :action => "whatnot" })
94
+ assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
95
+ link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot" })
96
+ assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&amp;b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
97
+ link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
98
+ end
99
+
100
+ def test_link_to_remote_html_options
101
+ assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outauthor</a>),
102
+ link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :class => "fine" } })
53
103
  end
54
104
 
55
105
  def test_periodically_call_remote
@@ -57,6 +107,13 @@ class PrototypeHelperTest < Test::Unit::TestCase
57
107
  periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
58
108
  end
59
109
 
110
+ def test_periodically_call_remote_with_frequency
111
+ assert_dom_equal(
112
+ "<script type=\"text/javascript\">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true})}, 2)\n//]]>\n</script>",
113
+ periodically_call_remote(:frequency => 2)
114
+ )
115
+ end
116
+
60
117
  def test_form_remote_tag
61
118
  assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
62
119
  form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
@@ -78,7 +135,50 @@ class PrototypeHelperTest < Test::Unit::TestCase
78
135
  form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) { _erbout.concat "Hello world!" }
79
136
  assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">Hello world!</form>), _erbout
80
137
  end
138
+
139
+ def test_remote_form_for_with_record_identification_with_new_record
140
+ _erbout = ''
141
+ remote_form_for(@record, {:html => { :id => 'create-author' }}) {}
142
+
143
+ expected = %(<form action='#{authors_path}' onsubmit="new Ajax.Request('#{authors_path}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_author' id='create-author' method='post'></form>)
144
+ assert_dom_equal expected, _erbout
145
+ end
146
+
147
+ def test_remote_form_for_with_record_identification_without_html_options
148
+ _erbout = ''
149
+ remote_form_for(@record) {}
150
+
151
+ expected = %(<form action='#{authors_path}' onsubmit="new Ajax.Request('#{authors_path}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_author' method='post' id='new_author'></form>)
152
+ assert_dom_equal expected, _erbout
153
+ end
154
+
155
+ def test_remote_form_for_with_record_identification_with_existing_record
156
+ @record.save
157
+ _erbout = ''
158
+ remote_form_for(@record) {}
159
+
160
+ expected = %(<form action='#{author_path(@record)}' id='edit_author_1' method='post' onsubmit="new Ajax.Request('#{author_path(@record)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_author'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>)
161
+ assert_dom_equal expected, _erbout
162
+ end
163
+
164
+ def test_remote_form_for_with_new_object_in_list
165
+ _erbout = ''
166
+ remote_form_for([@author, @article]) {}
167
+
168
+ expected = %(<form action='#{author_articles_path(@author)}' onsubmit="new Ajax.Request('#{author_articles_path(@author)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_article' method='post' id='new_article'></form>)
169
+ assert_dom_equal expected, _erbout
170
+ end
81
171
 
172
+ def test_remote_form_for_with_existing_object_in_list
173
+ @author.save
174
+ @article.save
175
+ _erbout = ''
176
+ remote_form_for([@author, @article]) {}
177
+
178
+ expected = %(<form action='#{author_article_path(@author, @article)}' id='edit_article_1' method='post' onsubmit="new Ajax.Request('#{author_article_path(@author, @article)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_article'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>)
179
+ assert_dom_equal expected, _erbout
180
+ end
181
+
82
182
  def test_on_callbacks
83
183
  callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure]
84
184
  callbacks.each do |callback|
@@ -129,6 +229,17 @@ class PrototypeHelperTest < Test::Unit::TestCase
129
229
  observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
130
230
  end
131
231
 
232
+ def test_observe_field_using_with_option
233
+ expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:'id=' + value})})\n//]]>\n</script>)
234
+ assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id')
235
+ assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + value")
236
+ end
237
+
238
+ def test_observe_field_using_json_in_with_option
239
+ expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:{'id':value}})})\n//]]>\n</script>)
240
+ assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "{'id':value}")
241
+ end
242
+
132
243
  def test_observe_field_using_function_for_callback
133
244
  assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {alert('Element changed')})\n//]]>\n</script>),
134
245
  observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')")
@@ -143,7 +254,12 @@ class PrototypeHelperTest < Test::Unit::TestCase
143
254
  assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {alert('Form changed')})\n//]]>\n</script>),
144
255
  observe_form("cart", :frequency => 2, :function => "alert('Form changed')")
145
256
  end
146
-
257
+
258
+ def test_observe_field_without_frequency
259
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.EventObserver('glass', function(element, value) {new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:value})})\n//]]>\n</script>),
260
+ observe_field("glass")
261
+ end
262
+
147
263
  def test_update_page
148
264
  block = Proc.new { |page| page.replace_html('foo', 'bar') }
149
265
  assert_equal create_generator(&block).to_s, update_page(&block)
@@ -159,6 +275,23 @@ class PrototypeHelperTest < Test::Unit::TestCase
159
275
  assert_equal javascript_tag(create_generator(&block).to_s, {:defer => 'true'}), update_page_tag({:defer => 'true'}, &block)
160
276
  end
161
277
 
278
+
279
+ protected
280
+ def author_path(record)
281
+ "/authors/#{record.id}"
282
+ end
283
+
284
+ def authors_path
285
+ "/authors"
286
+ end
287
+
288
+ def author_articles_path(author)
289
+ "/authors/#{author.id}/articles"
290
+ end
291
+
292
+ def author_article_path(author, article)
293
+ "/authors/#{author.id}/articles/#{article.id}"
294
+ end
162
295
  end
163
296
 
164
297
  class JavaScriptGeneratorTest < Test::Unit::TestCase
@@ -170,23 +303,23 @@ class JavaScriptGeneratorTest < Test::Unit::TestCase
170
303
  end
171
304
 
172
305
  def test_insert_html_with_string
173
- assert_equal 'new Insertion.Top("element", "\074p\076This is a test\074/p\076");',
306
+ assert_equal 'new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
174
307
  @generator.insert_html(:top, 'element', '<p>This is a test</p>')
175
- assert_equal 'new Insertion.Bottom("element", "\074p\076This is a test\074/p\076");',
308
+ assert_equal 'new Insertion.Bottom("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");',
176
309
  @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
177
- assert_equal 'new Insertion.Before("element", "\074p\076This is a test\074/p\076");',
310
+ assert_equal 'new Insertion.Before("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");',
178
311
  @generator.insert_html(:before, 'element', '<p>This is a test</p>')
179
- assert_equal 'new Insertion.After("element", "\074p\076This is a test\074/p\076");',
312
+ assert_equal 'new Insertion.After("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");',
180
313
  @generator.insert_html(:after, 'element', '<p>This is a test</p>')
181
314
  end
182
315
 
183
316
  def test_replace_html_with_string
184
- assert_equal 'Element.update("element", "\074p\076This is a test\074/p\076");',
317
+ assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
185
318
  @generator.replace_html('element', '<p>This is a test</p>')
186
319
  end
187
320
 
188
321
  def test_replace_element_with_string
189
- assert_equal 'Element.replace("element", "\074div id=\"element\"\076\074p\076This is a test\074/p\076\074/div\076");',
322
+ assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");',
190
323
  @generator.replace('element', '<div id="element"><p>This is a test</p></div>')
191
324
  end
192
325
 
@@ -241,18 +374,23 @@ class JavaScriptGeneratorTest < Test::Unit::TestCase
241
374
  @generator.remove('foo', 'bar')
242
375
  @generator.replace_html('baz', '<p>This is a test</p>')
243
376
 
244
- expected = %q(new Insertion.Top("element", "\074p\076This is a test\074/p\076");
245
- new Insertion.Bottom("element", "\074p\076This is a test\074/p\076");
377
+ assert_equal <<-EOS.chomp, @generator.to_s
378
+ new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
379
+ new Insertion.Bottom("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
246
380
  ["foo", "bar"].each(Element.remove);
247
- Element.update("baz", "\074p\076This is a test\074/p\076");)
248
-
249
- assert_equal expected, @generator.to_s
381
+ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
382
+ EOS
250
383
  end
251
384
 
252
385
  def test_element_access
253
386
  assert_equal %($("hello");), @generator['hello']
254
387
  end
255
388
 
389
+ def test_element_access_on_records
390
+ assert_equal %($("bunny_5");), @generator[Bunny.new(:id => 5)]
391
+ assert_equal %($("new_bunny");), @generator[Bunny.new]
392
+ end
393
+
256
394
  def test_element_proxy_one_deep
257
395
  @generator['hello'].hide
258
396
  assert_equal %($("hello").hide();), @generator.to_s
@@ -423,6 +561,29 @@ return (value.className == "welcome");
423
561
  EOS
424
562
  end
425
563
 
564
+ def test_collection_proxy_with_in_groups_of
565
+ @generator.select('p').in_groups_of('a', 3)
566
+ @generator.select('p').in_groups_of('a', 3, 'x')
567
+ assert_equal <<-EOS.strip, @generator.to_s
568
+ var a = $$("p").inGroupsOf(3);
569
+ var a = $$("p").inGroupsOf(3, "x");
570
+ EOS
571
+ end
572
+
573
+ def test_collection_proxy_with_each_slice
574
+ @generator.select('p').each_slice('a', 3)
575
+ @generator.select('p').each_slice('a', 3) do |group, index|
576
+ group.reverse
577
+ end
578
+
579
+ assert_equal <<-EOS.strip, @generator.to_s
580
+ var a = $$("p").eachSlice(3);
581
+ var a = $$("p").eachSlice(3, function(value, index) {
582
+ return value.reverse();
583
+ });
584
+ EOS
585
+ end
586
+
426
587
  def test_debug_rjs
427
588
  ActionView::Base.debug_rjs = true
428
589
  @generator['welcome'].replace_html 'Welcome'