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,37 +0,0 @@
1
- module ActionView
2
- module Helpers
3
- module PrototypeHelper
4
-
5
- # Method to execute an element update using Prototype.
6
- # DEPRECATION WARNING: This helper has been depercated; use RJS instead.
7
- # See ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods for more information.
8
- def update_element_function(element_id, options = {}, &block)
9
- content = escape_javascript(options[:content] || '')
10
- content = escape_javascript(capture(&block)) if block
11
-
12
- javascript_function = case (options[:action] || :update)
13
- when :update
14
- if options[:position]
15
- "new Insertion.#{options[:position].to_s.camelize}('#{element_id}','#{content}')"
16
- else
17
- "$('#{element_id}').innerHTML = '#{content}'"
18
- end
19
-
20
- when :empty
21
- "$('#{element_id}').innerHTML = ''"
22
-
23
- when :remove
24
- "Element.remove('#{element_id}')"
25
-
26
- else
27
- raise ArgumentError, "Invalid action, choose one of :update, :remove, :empty"
28
- end
29
-
30
- javascript_function << ";\n"
31
- options[:binding] ? concat(javascript_function, options[:binding]) : javascript_function
32
- end
33
- deprecate :update_element_function => "use RJS instead"
34
-
35
- end
36
- end
37
- end
@@ -1,233 +0,0 @@
1
- require File.dirname(__FILE__) + '/tag_helper'
2
-
3
- module ActionView
4
- module Helpers
5
- # Provides a set of helpers for creating JavaScript macros that rely on and often bundle methods from JavaScriptHelper into
6
- # larger units. These macros also rely on counterparts in the controller that provide them with their backing. The in-place
7
- # editing relies on ActionController::Base.in_place_edit_for and the autocompletion relies on
8
- # ActionController::Base.auto_complete_for.
9
- module JavaScriptMacrosHelper
10
- # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.
11
- #
12
- # Makes an HTML element specified by the DOM ID +field_id+ become an in-place
13
- # editor of a property.
14
- #
15
- # A form is automatically created and displayed when the user clicks the element,
16
- # something like this:
17
- # <form id="myElement-in-place-edit-form" target="specified url">
18
- # <input name="value" text="The content of myElement"/>
19
- # <input type="submit" value="ok"/>
20
- # <a onclick="javascript to cancel the editing">cancel</a>
21
- # </form>
22
- #
23
- # The form is serialized and sent to the server using an AJAX call, the action on
24
- # the server should process the value and return the updated value in the body of
25
- # the reponse. The element will automatically be updated with the changed value
26
- # (as returned from the server).
27
- #
28
- # Required +options+ are:
29
- # <tt>:url</tt>:: Specifies the url where the updated value should
30
- # be sent after the user presses "ok".
31
- #
32
- # Addtional +options+ are:
33
- # <tt>:rows</tt>:: Number of rows (more than 1 will use a TEXTAREA)
34
- # <tt>:cols</tt>:: Number of characters the text input should span (works for both INPUT and TEXTAREA)
35
- # <tt>:size</tt>:: Synonym for :cols when using a single line text input.
36
- # <tt>:cancel_text</tt>:: The text on the cancel link. (default: "cancel")
37
- # <tt>:save_text</tt>:: The text on the save link. (default: "ok")
38
- # <tt>:loading_text</tt>:: The text to display while the data is being loaded from the server (default: "Loading...")
39
- # <tt>:saving_text</tt>:: The text to display when submitting to the server (default: "Saving...")
40
- # <tt>:external_control</tt>:: The id of an external control used to enter edit mode.
41
- # <tt>:load_text_url</tt>:: URL where initial value of editor (content) is retrieved.
42
- # <tt>:options</tt>:: Pass through options to the AJAX call (see prototype's Ajax.Updater)
43
- # <tt>:with</tt>:: JavaScript snippet that should return what is to be sent
44
- # in the AJAX call, +form+ is an implicit parameter
45
- # <tt>:script</tt>:: Instructs the in-place editor to evaluate the remote JavaScript response (default: false)
46
- # <tt>:click_to_edit_text</tt>::The text shown during mouseover the editable text (default: "Click to edit")
47
- def in_place_editor(field_id, options = {})
48
- function = "new Ajax.InPlaceEditor("
49
- function << "'#{field_id}', "
50
- function << "'#{url_for(options[:url])}'"
51
-
52
- js_options = {}
53
- js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]
54
- js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]
55
- js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]
56
- js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text]
57
- js_options['rows'] = options[:rows] if options[:rows]
58
- js_options['cols'] = options[:cols] if options[:cols]
59
- js_options['size'] = options[:size] if options[:size]
60
- js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]
61
- js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]
62
- js_options['ajaxOptions'] = options[:options] if options[:options]
63
- js_options['evalScripts'] = options[:script] if options[:script]
64
- js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with]
65
- js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]
66
- function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
67
-
68
- function << ')'
69
-
70
- javascript_tag(function)
71
- end
72
-
73
- # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.
74
- #
75
- # Renders the value of the specified object and method with in-place editing capabilities.
76
- #
77
- # See the RDoc on ActionController::InPlaceEditing to learn more about this.
78
- def in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {})
79
- tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
80
- tag_options = {:tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)
81
- in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })
82
- tag.to_content_tag(tag_options.delete(:tag), tag_options) +
83
- in_place_editor(tag_options[:id], in_place_editor_options)
84
- end
85
-
86
- # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.
87
- #
88
- # Adds AJAX autocomplete functionality to the text input field with the
89
- # DOM ID specified by +field_id+.
90
- #
91
- # This function expects that the called action returns an HTML <ul> list,
92
- # or nothing if no entries should be displayed for autocompletion.
93
- #
94
- # You'll probably want to turn the browser's built-in autocompletion off,
95
- # so be sure to include an <tt>autocomplete="off"</tt> attribute with your text
96
- # input field.
97
- #
98
- # The autocompleter object is assigned to a Javascript variable named <tt>field_id</tt>_auto_completer.
99
- # This object is useful if you for example want to trigger the auto-complete suggestions through
100
- # other means than user input (for that specific case, call the <tt>activate</tt> method on that object).
101
- #
102
- # Required +options+ are:
103
- # <tt>:url</tt>:: URL to call for autocompletion results
104
- # in url_for format.
105
- #
106
- # Addtional +options+ are:
107
- # <tt>:update</tt>:: Specifies the DOM ID of the element whose
108
- # innerHTML should be updated with the autocomplete
109
- # entries returned by the AJAX request.
110
- # Defaults to <tt>field_id</tt> + '_auto_complete'
111
- # <tt>:with</tt>:: A JavaScript expression specifying the
112
- # parameters for the XMLHttpRequest. This defaults
113
- # to 'fieldname=value'.
114
- # <tt>:frequency</tt>:: Determines the time to wait after the last keystroke
115
- # for the AJAX request to be initiated.
116
- # <tt>:indicator</tt>:: Specifies the DOM ID of an element which will be
117
- # displayed while autocomplete is running.
118
- # <tt>:tokens</tt>:: A string or an array of strings containing
119
- # separator tokens for tokenized incremental
120
- # autocompletion. Example: <tt>:tokens => ','</tt> would
121
- # allow multiple autocompletion entries, separated
122
- # by commas.
123
- # <tt>:min_chars</tt>:: The minimum number of characters that should be
124
- # in the input field before an Ajax call is made
125
- # to the server.
126
- # <tt>:on_hide</tt>:: A Javascript expression that is called when the
127
- # autocompletion div is hidden. The expression
128
- # should take two variables: element and update.
129
- # Element is a DOM element for the field, update
130
- # is a DOM element for the div from which the
131
- # innerHTML is replaced.
132
- # <tt>:on_show</tt>:: Like on_hide, only now the expression is called
133
- # then the div is shown.
134
- # <tt>:after_update_element</tt>:: A Javascript expression that is called when the
135
- # user has selected one of the proposed values.
136
- # The expression should take two variables: element and value.
137
- # Element is a DOM element for the field, value
138
- # is the value selected by the user.
139
- # <tt>:select</tt>:: Pick the class of the element from which the value for
140
- # insertion should be extracted. If this is not specified,
141
- # the entire element is used.
142
- def auto_complete_field(field_id, options = {})
143
- function = "var #{field_id}_auto_completer = new Ajax.Autocompleter("
144
- function << "'#{field_id}', "
145
- function << "'" + (options[:update] || "#{field_id}_auto_complete") + "', "
146
- function << "'#{url_for(options[:url])}'"
147
-
148
- js_options = {}
149
- js_options[:tokens] = array_or_string_for_javascript(options[:tokens]) if options[:tokens]
150
- js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with]
151
- js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator]
152
- js_options[:select] = "'#{options[:select]}'" if options[:select]
153
- js_options[:paramName] = "'#{options[:param_name]}'" if options[:param_name]
154
- js_options[:frequency] = "#{options[:frequency]}" if options[:frequency]
155
-
156
- { :after_update_element => :afterUpdateElement,
157
- :on_show => :onShow, :on_hide => :onHide, :min_chars => :minChars }.each do |k,v|
158
- js_options[v] = options[k] if options[k]
159
- end
160
-
161
- function << (', ' + options_for_javascript(js_options) + ')')
162
-
163
- javascript_tag(function)
164
- end
165
-
166
- # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.
167
- #
168
- # Use this method in your view to generate a return for the AJAX autocomplete requests.
169
- #
170
- # Example action:
171
- #
172
- # def auto_complete_for_item_title
173
- # @items = Item.find(:all,
174
- # :conditions => [ 'LOWER(description) LIKE ?',
175
- # '%' + request.raw_post.downcase + '%' ])
176
- # render :inline => "<%= auto_complete_result(@items, 'description') %>"
177
- # end
178
- #
179
- # The auto_complete_result can of course also be called from a view belonging to the
180
- # auto_complete action if you need to decorate it further.
181
- def auto_complete_result(entries, field, phrase = nil)
182
- return unless entries
183
- items = entries.map { |entry| content_tag("li", phrase ? highlight(entry[field], phrase) : h(entry[field])) }
184
- content_tag("ul", items.uniq)
185
- end
186
-
187
- # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.
188
- #
189
- # Wrapper for text_field with added AJAX autocompletion functionality.
190
- #
191
- # In your controller, you'll need to define an action called
192
- # auto_complete_for to respond the AJAX calls,
193
- #
194
- # See the RDoc on ActionController::Macros::AutoComplete to learn more about this.
195
- def text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})
196
- (completion_options[:skip_style] ? "" : auto_complete_stylesheet) +
197
- text_field(object, method, tag_options) +
198
- content_tag("div", "", :id => "#{object}_#{method}_auto_complete", :class => "auto_complete") +
199
- auto_complete_field("#{object}_#{method}", { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options))
200
- end
201
-
202
- private
203
- def auto_complete_stylesheet
204
- content_tag('style', <<-EOT, :type => 'text/css')
205
- div.auto_complete {
206
- width: 350px;
207
- background: #fff;
208
- }
209
- div.auto_complete ul {
210
- border:1px solid #888;
211
- margin:0;
212
- padding:0;
213
- width:100%;
214
- list-style-type:none;
215
- }
216
- div.auto_complete ul li {
217
- margin:0;
218
- padding:3px;
219
- }
220
- div.auto_complete ul li.selected {
221
- background-color: #ffb;
222
- }
223
- div.auto_complete ul strong.highlight {
224
- color: #800;
225
- margin:0;
226
- padding:0;
227
- }
228
- EOT
229
- end
230
-
231
- end
232
- end
233
- end
@@ -1,86 +0,0 @@
1
- module ActionView
2
- module Helpers
3
- # Provides methods for linking to ActionController::Pagination objects.
4
- #
5
- # You can also build your links manually, like in this example:
6
- #
7
- # <%= link_to "Previous page", { :page => paginator.current.previous } if paginator.current.previous %>
8
- #
9
- # <%= link_to "Next page", { :page => paginator.current.next } if paginator.current.next %>
10
- module PaginationHelper
11
- unless const_defined?(:DEFAULT_OPTIONS)
12
- DEFAULT_OPTIONS = {
13
- :name => :page,
14
- :window_size => 2,
15
- :always_show_anchors => true,
16
- :link_to_current_page => false,
17
- :params => {}
18
- }
19
- end
20
-
21
- # Creates a basic HTML link bar for the given +paginator+.
22
- # +html_options+ are passed to +link_to+.
23
- #
24
- # +options+ are:
25
- # <tt>:name</tt>:: the routing name for this paginator
26
- # (defaults to +page+)
27
- # <tt>:window_size</tt>:: the number of pages to show around
28
- # the current page (defaults to +2+)
29
- # <tt>:always_show_anchors</tt>:: whether or not the first and last
30
- # pages should always be shown
31
- # (defaults to +true+)
32
- # <tt>:link_to_current_page</tt>:: whether or not the current page
33
- # should be linked to (defaults to
34
- # +false+)
35
- # <tt>:params</tt>:: any additional routing parameters
36
- # for page URLs
37
- def pagination_links(paginator, options={}, html_options={})
38
- name = options[:name] || DEFAULT_OPTIONS[:name]
39
- params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
40
-
41
- pagination_links_each(paginator, options) do |n|
42
- params[name] = n
43
- link_to(n.to_s, params, html_options)
44
- end
45
- end
46
-
47
- # Iterate through the pages of a given +paginator+, invoking a
48
- # block for each page number that needs to be rendered as a link.
49
- def pagination_links_each(paginator, options)
50
- options = DEFAULT_OPTIONS.merge(options)
51
- link_to_current_page = options[:link_to_current_page]
52
- always_show_anchors = options[:always_show_anchors]
53
-
54
- current_page = paginator.current_page
55
- window_pages = current_page.window(options[:window_size]).pages
56
- return if window_pages.length <= 1 unless link_to_current_page
57
-
58
- first, last = paginator.first, paginator.last
59
-
60
- html = ''
61
- if always_show_anchors and not (wp_first = window_pages[0]).first?
62
- html << yield(first.number)
63
- html << ' ... ' if wp_first.number - first.number > 1
64
- html << ' '
65
- end
66
-
67
- window_pages.each do |page|
68
- if current_page == page && !link_to_current_page
69
- html << page.number.to_s
70
- else
71
- html << yield(page.number)
72
- end
73
- html << ' '
74
- end
75
-
76
- if always_show_anchors and not (wp_last = window_pages[-1]).last?
77
- html << ' ... ' if last.number - wp_last.number > 1
78
- html << yield(last.number)
79
- end
80
-
81
- html
82
- end
83
-
84
- end # PaginationHelper
85
- end # Helpers
86
- end # ActionView
@@ -1,92 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../active_record_unit"
2
-
3
- class ActiveRecordAssertionsController < ActionController::Base
4
- self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
5
-
6
- # fail with 1 bad column
7
- def nasty_columns_1
8
- @company = Company.new
9
- @company.name = "B"
10
- @company.rating = 2
11
- render :inline => "snicker...."
12
- end
13
-
14
- # fail with 2 bad columns
15
- def nasty_columns_2
16
- @company = Company.new
17
- @company.name = ""
18
- @company.rating = 2
19
- render :inline => "double snicker...."
20
- end
21
-
22
- # this will pass validation
23
- def good_company
24
- @company = Company.new
25
- @company.name = "A"
26
- @company.rating = 69
27
- render :inline => "Goodness Gracious!"
28
- end
29
-
30
- # this will fail validation
31
- def bad_company
32
- @company = Company.new
33
- render :inline => "Who's Bad?"
34
- end
35
-
36
- # the safety dance......
37
- def rescue_action(e) raise; end
38
- end
39
-
40
- class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
41
- fixtures :companies
42
-
43
- def setup
44
- @request = ActionController::TestRequest.new
45
- @response = ActionController::TestResponse.new
46
- @controller = ActiveRecordAssertionsController.new
47
- super
48
- end
49
-
50
- # test for 1 bad apple column
51
- def test_some_invalid_columns
52
- process :nasty_columns_1
53
- assert_response :success
54
-
55
- assert_deprecated_assertion { assert_invalid_record 'company' }
56
- assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'rating' }
57
- assert_deprecated_assertion { assert_valid_column_on_record 'company', 'name' }
58
- assert_deprecated_assertion { assert_valid_column_on_record 'company', %w(name id) }
59
- end
60
-
61
- # test for 2 bad apples columns
62
- def test_all_invalid_columns
63
- process :nasty_columns_2
64
- assert_response :success
65
-
66
- assert_deprecated_assertion { assert_invalid_record 'company' }
67
- assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'rating' }
68
- assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'name' }
69
- assert_deprecated_assertion { assert_invalid_column_on_record 'company', %w(name rating) }
70
- end
71
-
72
- # ensure we have no problems with an ActiveRecord
73
- def test_valid_record
74
- process :good_company
75
- assert_response :success
76
-
77
- assert_deprecated_assertion { assert_valid_record 'company' }
78
- end
79
-
80
- # ensure we have problems with an ActiveRecord
81
- def test_invalid_record
82
- process :bad_company
83
- assert_response :success
84
-
85
- assert_deprecated_assertion { assert_invalid_record 'company' }
86
- end
87
-
88
- protected
89
- def assert_deprecated_assertion(message = nil, &block)
90
- assert_deprecated(/assert_.*from test_/, &block)
91
- end
92
- end