actionpack 1.13.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (317) hide show
  1. data/CHANGELOG +1400 -20
  2. data/MIT-LICENSE +1 -1
  3. data/README +5 -5
  4. data/RUNNING_UNIT_TESTS +4 -5
  5. data/Rakefile +5 -6
  6. data/install.rb +2 -2
  7. data/lib/action_controller.rb +11 -15
  8. data/lib/action_controller/assertions.rb +12 -25
  9. data/lib/action_controller/assertions/dom_assertions.rb +18 -4
  10. data/lib/action_controller/assertions/model_assertions.rb +8 -1
  11. data/lib/action_controller/assertions/response_assertions.rb +35 -12
  12. data/lib/action_controller/assertions/routing_assertions.rb +56 -12
  13. data/lib/action_controller/assertions/selector_assertions.rb +105 -38
  14. data/lib/action_controller/assertions/tag_assertions.rb +28 -15
  15. data/lib/action_controller/base.rb +318 -250
  16. data/lib/action_controller/benchmarking.rb +33 -29
  17. data/lib/action_controller/caching.rb +130 -64
  18. data/lib/action_controller/cgi_ext.rb +16 -0
  19. data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
  20. data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
  21. data/lib/action_controller/cgi_ext/session.rb +73 -0
  22. data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
  23. data/lib/action_controller/cgi_process.rb +34 -57
  24. data/lib/action_controller/components.rb +19 -36
  25. data/lib/action_controller/cookies.rb +10 -9
  26. data/lib/action_controller/dispatcher.rb +195 -0
  27. data/lib/action_controller/filters.rb +35 -34
  28. data/lib/action_controller/flash.rb +30 -35
  29. data/lib/action_controller/helpers.rb +121 -47
  30. data/lib/action_controller/http_authentication.rb +126 -0
  31. data/lib/action_controller/integration.rb +105 -101
  32. data/lib/action_controller/layout.rb +59 -47
  33. data/lib/action_controller/mime_responds.rb +57 -68
  34. data/lib/action_controller/mime_type.rb +43 -80
  35. data/lib/action_controller/mime_types.rb +20 -0
  36. data/lib/action_controller/polymorphic_routes.rb +88 -0
  37. data/lib/action_controller/record_identifier.rb +91 -0
  38. data/lib/action_controller/request.rb +553 -88
  39. data/lib/action_controller/request_forgery_protection.rb +126 -0
  40. data/lib/action_controller/request_profiler.rb +138 -0
  41. data/lib/action_controller/rescue.rb +185 -69
  42. data/lib/action_controller/resources.rb +211 -172
  43. data/lib/action_controller/response.rb +49 -8
  44. data/lib/action_controller/routing.rb +359 -236
  45. data/lib/action_controller/routing_optimisation.rb +119 -0
  46. data/lib/action_controller/session/active_record_store.rb +3 -2
  47. data/lib/action_controller/session/cookie_store.rb +161 -0
  48. data/lib/action_controller/session/mem_cache_store.rb +9 -16
  49. data/lib/action_controller/session_management.rb +17 -8
  50. data/lib/action_controller/streaming.rb +6 -3
  51. data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
  52. data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
  53. data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
  54. data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
  55. data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
  56. data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
  57. data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
  58. data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
  59. data/lib/action_controller/test_case.rb +53 -0
  60. data/lib/action_controller/test_process.rb +59 -46
  61. data/lib/action_controller/url_rewriter.rb +48 -24
  62. data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
  63. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
  64. data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
  65. data/lib/action_controller/verification.rb +27 -21
  66. data/lib/action_pack.rb +1 -1
  67. data/lib/action_pack/version.rb +4 -4
  68. data/lib/action_view.rb +2 -3
  69. data/lib/action_view/base.rb +218 -63
  70. data/lib/action_view/compiled_templates.rb +1 -2
  71. data/lib/action_view/helpers/active_record_helper.rb +35 -17
  72. data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
  73. data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
  74. data/lib/action_view/helpers/benchmark_helper.rb +12 -5
  75. data/lib/action_view/helpers/cache_helper.rb +29 -0
  76. data/lib/action_view/helpers/capture_helper.rb +97 -63
  77. data/lib/action_view/helpers/date_helper.rb +295 -35
  78. data/lib/action_view/helpers/debug_helper.rb +6 -2
  79. data/lib/action_view/helpers/form_helper.rb +354 -111
  80. data/lib/action_view/helpers/form_options_helper.rb +171 -109
  81. data/lib/action_view/helpers/form_tag_helper.rb +332 -76
  82. data/lib/action_view/helpers/javascript_helper.rb +35 -11
  83. data/lib/action_view/helpers/javascripts/controls.js +484 -354
  84. data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
  85. data/lib/action_view/helpers/javascripts/effects.js +396 -364
  86. data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
  87. data/lib/action_view/helpers/number_helper.rb +84 -60
  88. data/lib/action_view/helpers/prototype_helper.rb +419 -43
  89. data/lib/action_view/helpers/record_identification_helper.rb +20 -0
  90. data/lib/action_view/helpers/record_tag_helper.rb +59 -0
  91. data/lib/action_view/helpers/sanitize_helper.rb +223 -0
  92. data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
  93. data/lib/action_view/helpers/tag_helper.rb +69 -39
  94. data/lib/action_view/helpers/text_helper.rb +221 -148
  95. data/lib/action_view/helpers/url_helper.rb +283 -165
  96. data/lib/action_view/partials.rb +134 -62
  97. data/lib/action_view/template_error.rb +4 -12
  98. data/lib/actionpack.rb +1 -0
  99. data/test/abstract_unit.rb +21 -1
  100. data/test/action_view_test.rb +26 -0
  101. data/test/active_record_unit.rb +12 -20
  102. data/test/activerecord/active_record_store_test.rb +2 -2
  103. data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
  104. data/test/controller/action_pack_assertions_test.rb +21 -152
  105. data/test/controller/addresses_render_test.rb +2 -7
  106. data/test/controller/assert_select_test.rb +120 -14
  107. data/test/controller/base_test.rb +11 -13
  108. data/test/controller/caching_test.rb +125 -5
  109. data/test/controller/capture_test.rb +23 -16
  110. data/test/controller/cgi_test.rb +66 -391
  111. data/test/controller/components_test.rb +31 -42
  112. data/test/controller/content_type_test.rb +1 -1
  113. data/test/controller/cookie_test.rb +42 -14
  114. data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
  115. data/test/controller/dispatcher_test.rb +123 -0
  116. data/test/controller/fake_models.rb +5 -0
  117. data/test/controller/filters_test.rb +44 -7
  118. data/test/controller/flash_test.rb +46 -2
  119. data/test/controller/fragment_store_setting_test.rb +10 -8
  120. data/test/controller/helper_test.rb +19 -2
  121. data/test/controller/html-scanner/document_test.rb +124 -0
  122. data/test/controller/html-scanner/node_test.rb +69 -0
  123. data/test/controller/html-scanner/sanitizer_test.rb +250 -0
  124. data/test/controller/html-scanner/tag_node_test.rb +239 -0
  125. data/test/controller/html-scanner/text_node_test.rb +51 -0
  126. data/test/controller/html-scanner/tokenizer_test.rb +125 -0
  127. data/test/controller/http_authentication_test.rb +54 -0
  128. data/test/controller/integration_test.rb +12 -26
  129. data/test/controller/layout_test.rb +64 -12
  130. data/test/controller/mime_responds_test.rb +193 -38
  131. data/test/controller/mime_type_test.rb +30 -8
  132. data/test/controller/new_render_test.rb +104 -22
  133. data/test/controller/polymorphic_routes_test.rb +98 -0
  134. data/test/controller/record_identifier_test.rb +103 -0
  135. data/test/controller/redirect_test.rb +120 -18
  136. data/test/controller/render_test.rb +195 -45
  137. data/test/controller/request_forgery_protection_test.rb +217 -0
  138. data/test/controller/request_test.rb +545 -27
  139. data/test/controller/rescue_test.rb +501 -0
  140. data/test/controller/resources_test.rb +258 -132
  141. data/test/controller/routing_test.rb +502 -106
  142. data/test/controller/selector_test.rb +5 -5
  143. data/test/controller/send_file_test.rb +17 -7
  144. data/test/controller/session/cookie_store_test.rb +246 -0
  145. data/test/controller/session/mem_cache_store_test.rb +182 -0
  146. data/test/controller/session_fixation_test.rb +8 -11
  147. data/test/controller/session_management_test.rb +7 -7
  148. data/test/controller/test_test.rb +150 -38
  149. data/test/controller/url_rewriter_test.rb +87 -12
  150. data/test/controller/verification_test.rb +11 -0
  151. data/test/controller/view_paths_test.rb +137 -0
  152. data/test/controller/webservice_test.rb +11 -75
  153. data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
  154. data/test/fixtures/db_definitions/sqlite.sql +2 -1
  155. data/test/fixtures/developer.rb +2 -0
  156. data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
  157. data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
  158. data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
  159. data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
  160. data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
  161. data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
  162. data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
  163. data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
  164. data/test/fixtures/multipart/binary_file +0 -0
  165. data/test/fixtures/multipart/bracketed_param +5 -0
  166. data/test/fixtures/override/test/hello_world.erb +1 -0
  167. data/test/fixtures/override2/layouts/test/sub.erb +1 -0
  168. data/test/fixtures/post_test/layouts/post.html.erb +1 -0
  169. data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
  170. data/test/fixtures/post_test/post/index.html.erb +1 -0
  171. data/test/fixtures/post_test/post/index.iphone.erb +1 -0
  172. data/test/fixtures/post_test/super_post/index.html.erb +1 -0
  173. data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
  174. data/test/fixtures/public/404.html +1 -0
  175. data/test/fixtures/public/500.html +1 -0
  176. data/test/fixtures/public/javascripts/application.js +0 -1
  177. data/test/fixtures/public/javascripts/bank.js +1 -0
  178. data/test/fixtures/public/javascripts/robber.js +1 -0
  179. data/test/fixtures/public/stylesheets/bank.css +1 -0
  180. data/test/fixtures/public/stylesheets/robber.css +1 -0
  181. data/test/fixtures/replies.yml +2 -0
  182. data/test/fixtures/reply.rb +2 -1
  183. data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
  184. data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
  185. data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
  186. data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
  187. data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
  188. data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
  189. data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
  190. data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
  191. data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
  192. data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
  193. data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
  194. data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
  195. data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
  196. data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
  197. data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
  198. data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
  199. data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
  200. data/test/fixtures/test/_hash_greeting.erb +1 -0
  201. data/test/fixtures/test/_hash_object.erb +2 -0
  202. data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
  203. data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
  204. data/test/fixtures/test/_partial.erb +1 -0
  205. data/test/fixtures/test/_partial.html.erb +1 -0
  206. data/test/fixtures/test/_partial.js.erb +1 -0
  207. data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
  208. data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
  209. data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
  210. data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
  211. data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
  212. data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
  213. data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
  214. data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
  215. data/test/fixtures/test/content_for_concatenated.erb +3 -0
  216. data/test/fixtures/test/content_for_with_parameter.erb +2 -0
  217. data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
  218. data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
  219. data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
  220. data/test/fixtures/test/formatted_xml_erb.builder +1 -0
  221. data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
  222. data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
  223. data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
  224. data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
  225. data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
  226. data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
  227. data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
  228. data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
  229. data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
  230. data/test/fixtures/test/list.erb +1 -0
  231. data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
  232. data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
  233. data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
  234. data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
  235. data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
  236. data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
  237. data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
  238. data/test/fixtures/topic.rb +1 -1
  239. data/test/template/active_record_helper_test.rb +67 -20
  240. data/test/template/asset_tag_helper_test.rb +222 -54
  241. data/test/template/atom_feed_helper_test.rb +101 -0
  242. data/test/template/benchmark_helper_test.rb +2 -2
  243. data/test/template/compiled_templates_test.rb +76 -32
  244. data/test/template/date_helper_test.rb +125 -9
  245. data/test/template/form_helper_test.rb +326 -33
  246. data/test/template/form_options_helper_test.rb +822 -15
  247. data/test/template/form_tag_helper_test.rb +96 -30
  248. data/test/template/javascript_helper_test.rb +61 -13
  249. data/test/template/number_helper_test.rb +12 -11
  250. data/test/template/prototype_helper_test.rb +185 -24
  251. data/test/template/sanitize_helper_test.rb +49 -0
  252. data/test/template/scriptaculous_helper_test.rb +9 -3
  253. data/test/template/tag_helper_test.rb +13 -2
  254. data/test/template/text_helper_test.rb +38 -52
  255. data/test/template/url_helper_test.rb +216 -46
  256. metadata +144 -116
  257. data/examples/.htaccess +0 -24
  258. data/examples/address_book/index.rhtml +0 -33
  259. data/examples/address_book/layout.rhtml +0 -8
  260. data/examples/address_book_controller.cgi +0 -9
  261. data/examples/address_book_controller.fcgi +0 -6
  262. data/examples/address_book_controller.rb +0 -52
  263. data/examples/address_book_controller.rbx +0 -4
  264. data/examples/benchmark.rb +0 -52
  265. data/examples/benchmark_with_ar.fcgi +0 -89
  266. data/examples/blog_controller.cgi +0 -53
  267. data/examples/debate/index.rhtml +0 -14
  268. data/examples/debate/new_topic.rhtml +0 -22
  269. data/examples/debate/topic.rhtml +0 -32
  270. data/examples/debate_controller.cgi +0 -57
  271. data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
  272. data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
  273. data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
  274. data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
  275. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
  276. data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
  277. data/lib/action_controller/deprecated_dependencies.rb +0 -65
  278. data/lib/action_controller/deprecated_redirects.rb +0 -17
  279. data/lib/action_controller/deprecated_request_methods.rb +0 -34
  280. data/lib/action_controller/macros/auto_complete.rb +0 -53
  281. data/lib/action_controller/macros/in_place_editing.rb +0 -33
  282. data/lib/action_controller/pagination.rb +0 -408
  283. data/lib/action_controller/scaffolding.rb +0 -189
  284. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
  285. data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
  286. data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
  287. data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
  288. data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
  289. data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
  290. data/lib/action_controller/vendor/xml_node.rb +0 -97
  291. data/lib/action_view/helpers/deprecated_helper.rb +0 -37
  292. data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
  293. data/lib/action_view/helpers/pagination_helper.rb +0 -86
  294. data/test/activerecord/active_record_assertions_test.rb +0 -92
  295. data/test/activerecord/pagination_test.rb +0 -165
  296. data/test/controller/deprecated_instance_variables_test.rb +0 -48
  297. data/test/controller/raw_post_test.rb +0 -68
  298. data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
  299. data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
  300. data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
  301. data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
  302. data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
  303. data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
  304. data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
  305. data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
  306. data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
  307. data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
  308. data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
  309. data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
  310. data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
  311. data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
  312. data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
  313. data/test/fixtures/test/_hash_object.rhtml +0 -1
  314. data/test/fixtures/test/list.rhtml +0 -1
  315. data/test/template/deprecated_helper_test.rb +0 -36
  316. data/test/template/deprecated_instance_variables_test.rb +0 -43
  317. data/test/template/java_script_macros_helper_test.rb +0 -109
@@ -0,0 +1,101 @@
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
+
3
+ Scroll = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
4
+
5
+ class ScrollsController < ActionController::Base
6
+ FEEDS = {}
7
+ FEEDS["defaults"] = <<-EOT
8
+ atom_feed do |feed|
9
+ feed.title("My great blog!")
10
+ feed.updated((@scrolls.first.created_at))
11
+
12
+ for scroll in @scrolls
13
+ feed.entry(scroll) do |entry|
14
+ entry.title(scroll.title)
15
+ entry.content(scroll.body, :type => 'html')
16
+
17
+ entry.author do |author|
18
+ author.name("DHH")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ EOT
24
+ FEEDS["entry_options"] = <<-EOT
25
+ atom_feed do |feed|
26
+ feed.title("My great blog!")
27
+ feed.updated((@scrolls.first.created_at))
28
+
29
+ for scroll in @scrolls
30
+ feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
31
+ entry.title(scroll.title)
32
+ entry.content(scroll.body, :type => 'html')
33
+
34
+ entry.author do |author|
35
+ author.name("DHH")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ EOT
41
+
42
+ def index
43
+ @scrolls = [
44
+ Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)),
45
+ Scroll.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)),
46
+ ]
47
+
48
+ render :inline => FEEDS[params[:id]], :type => :builder
49
+ end
50
+ end
51
+
52
+ class AtomFeedTest < Test::Unit::TestCase
53
+ def setup
54
+ @request = ActionController::TestRequest.new
55
+ @response = ActionController::TestResponse.new
56
+ @controller = ScrollsController.new
57
+
58
+ @request.host = "www.nextangle.com"
59
+ end
60
+
61
+ def test_feed_should_use_default_language_if_none_is_given
62
+ with_restful_routing(:scrolls) do
63
+ get :index, :id => "defaults"
64
+ assert_match %r{xml:lang="en-US"}, @response.body
65
+ end
66
+ end
67
+
68
+ def test_feed_should_include_two_entries
69
+ with_restful_routing(:scrolls) do
70
+ get :index, :id => "defaults"
71
+ assert_select "entry", 2
72
+ end
73
+ end
74
+
75
+ def test_entry_should_only_use_published_if_created_at_is_present
76
+ with_restful_routing(:scrolls) do
77
+ get :index, :id => "defaults"
78
+ assert_select "published", 1
79
+ end
80
+ end
81
+
82
+ def test_entry_with_prefilled_options_should_use_those_instead_of_querying_the_record
83
+ with_restful_routing(:scrolls) do
84
+ get :index, :id => "entry_options"
85
+
86
+ assert_select "updated", Time.utc(2007, 1, 1).xmlschema
87
+ assert_select "updated", Time.utc(2007, 1, 2).xmlschema
88
+ end
89
+ end
90
+
91
+
92
+ private
93
+ def with_restful_routing(resources)
94
+ with_routing do |set|
95
+ set.draw do |map|
96
+ map.resources(resources)
97
+ end
98
+ yield
99
+ end
100
+ end
101
+ end
@@ -1,5 +1,5 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/benchmark_helper'
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
+ require 'action_view/helpers/benchmark_helper'
3
3
 
4
4
  class BenchmarkHelperTest < Test::Unit::TestCase
5
5
  include ActionView::Helpers::BenchmarkHelper
@@ -1,10 +1,8 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
3
- require File.dirname(__FILE__) + '/../../lib/action_view/compiled_templates'
4
- require File.dirname(__FILE__) + "/../abstract_unit"
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
2
+ require 'action_view/helpers/date_helper'
3
+ require 'action_view/compiled_templates'
5
4
 
6
5
  class CompiledTemplateTests < Test::Unit::TestCase
7
-
8
6
  def setup
9
7
  @ct = ActionView::CompiledTemplates.new
10
8
  @v = Class.new
@@ -15,7 +13,7 @@ class CompiledTemplateTests < Test::Unit::TestCase
15
13
  end
16
14
  def teardown
17
15
  [@a, @b, @s].each do |f|
18
- `rm #{f}` if File.exist?(f) || File.symlink?(f)
16
+ FileUtils.rm(f) if File.exist?(f) || File.symlink?(f)
19
17
  end
20
18
  end
21
19
  attr_reader :ct, :v
@@ -24,7 +22,7 @@ class CompiledTemplateTests < Test::Unit::TestCase
24
22
  hi_world = ct.method_names['hi world']
25
23
  hi_sexy = ct.method_names['hi sexy']
26
24
  wish_upon_a_star = ct.method_names['I love seeing decent error messages']
27
-
25
+
28
26
  assert_equal hi_world, ct.method_names['hi world']
29
27
  assert_equal hi_sexy, ct.method_names['hi sexy']
30
28
  assert_equal wish_upon_a_star, ct.method_names['I love seeing decent error messages']
@@ -70,68 +68,114 @@ class CompiledTemplateTests < Test::Unit::TestCase
70
68
  assert (t1..Time.now).include?(ct.mtime('doubling method', [:a]))
71
69
  end
72
70
 
71
+ uses_mocha 'test_compile_time' do
73
72
  def test_compile_time
73
+ t = Time.now
74
+
74
75
  File.open(@a, "w"){|f| f.puts @a}
75
76
  File.open(@b, "w"){|f| f.puts @b}
76
-
77
77
  # windows doesn't support symlinks (even under cygwin)
78
78
  windows = (RUBY_PLATFORM =~ /win32/)
79
79
  `ln -s #{@a} #{@s}` unless windows
80
80
 
81
81
  v = ActionView::Base.new
82
82
  v.base_path = '.'
83
- v.cache_template_loading = false;
83
+ v.cache_template_loading = false
84
84
 
85
- sleep 1
86
- t = Time.now
87
- sleep 1
85
+ # All templates were created at t+1
86
+ File::Stat.any_instance.expects(:mtime).times(windows ? 2 : 3).returns(t + 1.second)
87
+
88
+ # private methods template_changed_since? and compile_template?
89
+ # should report true for all since they have not been compiled
90
+ assert v.send(:template_changed_since?, @a, t)
91
+ assert v.send(:template_changed_since?, @b, t)
92
+ assert v.send(:template_changed_since?, @s, t) unless windows
93
+
94
+ assert v.send(:compile_template?, nil, @a, {})
95
+ assert v.send(:compile_template?, nil, @b, {})
96
+ assert v.send(:compile_template?, nil, @s, {}) unless windows
88
97
 
98
+ # All templates are rendered at t+2
99
+ Time.expects(:now).times(windows ? 2 : 3).returns(t + 2.seconds)
89
100
  v.compile_and_render_template(:rhtml, '', @a)
90
101
  v.compile_and_render_template(:rhtml, '', @b)
91
102
  v.compile_and_render_template(:rhtml, '', @s) unless windows
92
-
93
103
  a_n = v.method_names[@a]
94
104
  b_n = v.method_names[@b]
95
- s_n = v.method_names[@s] unless windows
96
- ct_a = v.compile_time[a_n]
97
- ct_b = v.compile_time[b_n]
98
- ct_s = v.compile_time[s_n] unless windows
105
+ s_n = v.method_names[@s] unless windows
99
106
  # all of the files have changed since last compile
100
107
  assert v.compile_time[a_n] > t
101
108
  assert v.compile_time[b_n] > t
102
109
  assert v.compile_time[s_n] > t unless windows
103
110
 
104
- sleep 1
111
+ # private methods template_changed_since? and compile_template?
112
+ # should report false for all since none have changed since compile
113
+ File::Stat.any_instance.expects(:mtime).times(windows ? 6 : 12).returns(t + 1.second)
114
+ assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
115
+ assert !v.send(:template_changed_since?, @b, v.compile_time[b_n])
116
+ assert !v.send(:template_changed_since?, @s, v.compile_time[s_n]) unless windows
117
+ assert !v.send(:compile_template?, nil, @a, {})
118
+ assert !v.send(:compile_template?, nil, @b, {})
119
+ assert !v.send(:compile_template?, nil, @s, {}) unless windows
105
120
  v.compile_and_render_template(:rhtml, '', @a)
106
121
  v.compile_and_render_template(:rhtml, '', @b)
107
- v.compile_and_render_template(:rhtml, '', @s) unless windows
122
+ v.compile_and_render_template(:rhtml, '', @s) unless windows
108
123
  # none of the files have changed since last compile
109
- # so they should not have been recmpiled
110
- assert_equal ct_a, v.compile_time[a_n]
111
- assert_equal ct_b, v.compile_time[b_n]
112
- assert_equal ct_s, v.compile_time[s_n] unless windows
124
+ assert v.compile_time[a_n] < t + 3.seconds
125
+ assert v.compile_time[b_n] < t + 3.seconds
126
+ assert v.compile_time[s_n] < t + 3.seconds unless windows
113
127
 
114
128
  `rm #{@s}; ln -s #{@b} #{@s}` unless windows
129
+ # private methods template_changed_since? and compile_template?
130
+ # should report true for symlink since it has changed since compile
131
+
132
+ # t + 3.seconds is for the symlink
133
+ File::Stat.any_instance.expects(:mtime).times(windows ? 6 : 9).returns(
134
+ *(windows ? [ t + 1.second, t + 1.second ] :
135
+ [ t + 1.second, t + 1.second, t + 3.second ]) * 3)
136
+ assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
137
+ assert !v.send(:template_changed_since?, @b, v.compile_time[b_n])
138
+ assert v.send(:template_changed_since?, @s, v.compile_time[s_n]) unless windows
139
+ assert !v.send(:compile_template?, nil, @a, {})
140
+ assert !v.send(:compile_template?, nil, @b, {})
141
+ assert v.send(:compile_template?, nil, @s, {}) unless windows
142
+
143
+ # Only the symlink template gets rendered at t+3
144
+ Time.stubs(:now).returns(t + 3.seconds) unless windows
115
145
  v.compile_and_render_template(:rhtml, '', @a)
116
146
  v.compile_and_render_template(:rhtml, '', @b)
117
147
  v.compile_and_render_template(:rhtml, '', @s) unless windows
118
148
  # the symlink has changed since last compile
119
- assert_equal ct_a, v.compile_time[a_n]
120
- assert_equal ct_b, v.compile_time[b_n]
121
- assert v.compile_time[s_n] > t unless windows
149
+ assert v.compile_time[a_n] < t + 3.seconds
150
+ assert v.compile_time[b_n] < t + 3.seconds
151
+ assert_equal v.compile_time[s_n], t + 3.seconds unless windows
122
152
 
123
- sleep 1
124
153
  FileUtils.touch @b
125
- t = Time.now
126
- sleep 1
154
+ # private methods template_changed_since? and compile_template?
155
+ # should report true for symlink and file at end of symlink
156
+ # since it has changed since last compile
157
+ #
158
+ # t+4 is for @b and also for the file that @s points to, which is @b
159
+ File::Stat.any_instance.expects(:mtime).times(windows ? 6 : 12).returns(
160
+ *(windows ? [ t + 1.second, t + 4.seconds ] :
161
+ [ t + 1.second, t + 4.seconds, t + 3.second, t + 4.seconds ]) * 3)
162
+ assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
163
+ assert v.send(:template_changed_since?, @b, v.compile_time[b_n])
164
+ assert v.send(:template_changed_since?, @s, v.compile_time[s_n]) unless windows
165
+ assert !v.send(:compile_template?, nil, @a, {})
166
+ assert v.send(:compile_template?, nil, @b, {})
167
+ assert v.send(:compile_template?, nil, @s, {}) unless windows
168
+
169
+ Time.expects(:now).times(windows ? 1 : 2).returns(t + 5.seconds)
127
170
  v.compile_and_render_template(:rhtml, '', @a)
128
171
  v.compile_and_render_template(:rhtml, '', @b)
129
172
  v.compile_and_render_template(:rhtml, '', @s) unless windows
130
173
  # the file at the end of the symlink has changed since last compile
131
174
  # both the symlink and the file at the end of it should be recompiled
132
- assert v.compile_time[a_n] < t
133
- assert v.compile_time[b_n] > t
134
- assert v.compile_time[s_n] > t unless windows
175
+ assert v.compile_time[a_n] < t + 5.seconds
176
+ assert_equal v.compile_time[b_n], t + 5.seconds
177
+ assert_equal v.compile_time[s_n], t + 5.seconds unless windows
178
+ end
135
179
  end
136
180
  end
137
181
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + "/../abstract_unit"
1
+ require "#{File.dirname(__FILE__)}/../abstract_unit"
3
2
 
4
3
  class DateHelperTest < Test::Unit::TestCase
5
4
  include ActionView::Helpers::DateHelper
@@ -14,11 +13,14 @@ class DateHelperTest < Test::Unit::TestCase
14
13
  def id_before_type_cast
15
14
  123
16
15
  end
16
+ def to_param
17
+ '123'
18
+ end
17
19
  end
18
20
  end
19
21
 
20
22
  def test_distance_in_words
21
- from = Time.mktime(2004, 3, 6, 21, 45, 0)
23
+ from = Time.mktime(2004, 6, 6, 21, 45, 0)
22
24
 
23
25
  # 0..1 with include_seconds
24
26
  assert_equal "less than 5 seconds", distance_of_time_in_words(from, from + 0.seconds, true)
@@ -64,16 +66,16 @@ class DateHelperTest < Test::Unit::TestCase
64
66
  assert_equal "about 1 month", distance_of_time_in_words(from, from + 29.days + 23.hours + 59.minutes + 30.seconds)
65
67
  assert_equal "about 1 month", distance_of_time_in_words(from, from + 59.days + 23.hours + 59.minutes + 29.seconds)
66
68
 
67
- # 86400..525959
69
+ # 86400..525599
68
70
  assert_equal "2 months", distance_of_time_in_words(from, from + 59.days + 23.hours + 59.minutes + 30.seconds)
69
71
  assert_equal "12 months", distance_of_time_in_words(from, from + 1.years - 31.seconds)
70
72
 
71
- # 525960..1051919
73
+ # 525600..1051199
72
74
  assert_equal "about 1 year", distance_of_time_in_words(from, from + 1.years - 30.seconds)
73
75
  assert_equal "about 1 year", distance_of_time_in_words(from, from + 2.years - 31.seconds)
74
76
 
75
- # > 1051920
76
- assert_equal "over 2 years", distance_of_time_in_words(from, from + 2.years - 30.seconds)
77
+ # > 1051199
78
+ assert_equal "over 2 years", distance_of_time_in_words(from, from + 2.years + 30.seconds)
77
79
  assert_equal "over 10 years", distance_of_time_in_words(from, from + 10.years)
78
80
 
79
81
  # test to < from
@@ -94,8 +96,7 @@ class DateHelperTest < Test::Unit::TestCase
94
96
  end
95
97
 
96
98
  def test_time_ago_in_words
97
- t = Time.now - 1.years
98
- assert_equal "about 1 year", time_ago_in_words(t)
99
+ assert_equal "about 1 year", time_ago_in_words(1.year.ago - 1.day)
99
100
  end
100
101
 
101
102
  def test_select_day
@@ -226,6 +227,14 @@ class DateHelperTest < Test::Unit::TestCase
226
227
  assert_equal expected, select_month(8, :use_month_names => month_names)
227
228
  end
228
229
 
230
+ def test_select_month_with_hidden
231
+ assert_dom_equal "<input type=\"hidden\" id=\"date_month\" name=\"date[month]\" value=\"8\" />\n", select_month(8, :use_hidden => true)
232
+ end
233
+
234
+ def test_select_month_with_hidden_and_field_name
235
+ assert_dom_equal "<input type=\"hidden\" id=\"date_mois\" name=\"date[mois]\" value=\"8\" />\n", select_month(8, :use_hidden => true, :field_name => 'mois')
236
+ end
237
+
229
238
  def test_select_year
230
239
  expected = %(<select id="date_year" name="date[year]">\n)
231
240
  expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n)
@@ -273,6 +282,14 @@ class DateHelperTest < Test::Unit::TestCase
273
282
  assert_equal expected, select_year(2005, :start_year => 2005, :end_year => 2003)
274
283
  end
275
284
 
285
+ def test_select_year_with_hidden
286
+ assert_dom_equal "<input type=\"hidden\" id=\"date_year\" name=\"date[year]\" value=\"2007\" />\n", select_year(2007, :use_hidden => true)
287
+ end
288
+
289
+ def test_select_year_with_hidden_and_field_name
290
+ assert_dom_equal "<input type=\"hidden\" id=\"date_anno\" name=\"date[anno]\" value=\"2007\" />\n", select_year(2007, :use_hidden => true, :field_name => 'anno')
291
+ end
292
+
276
293
  def test_select_hour
277
294
  expected = %(<select id="date_hour" name="date[hour]">\n)
278
295
  expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n)
@@ -369,6 +386,14 @@ class DateHelperTest < Test::Unit::TestCase
369
386
  assert_equal expected, select_minute(nil, { :include_blank => true , :minute_step => 15 })
370
387
  end
371
388
 
389
+ def test_select_minute_with_hidden
390
+ assert_dom_equal "<input type=\"hidden\" id=\"date_minute\" name=\"date[minute]\" value=\"8\" />\n", select_minute(8, :use_hidden => true)
391
+ end
392
+
393
+ def test_select_minute_with_hidden_and_field_name
394
+ assert_dom_equal "<input type=\"hidden\" id=\"date_minuto\" name=\"date[minuto]\" value=\"8\" />\n", select_minute(8, :use_hidden => true, :field_name => 'minuto')
395
+ end
396
+
372
397
  def test_select_second
373
398
  expected = %(<select id="date_second" name="date[second]">\n)
374
399
  expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n)
@@ -786,6 +811,23 @@ class DateHelperTest < Test::Unit::TestCase
786
811
  assert_equal expected, date_select("post", "written_on")
787
812
  end
788
813
 
814
+ def test_date_select_without_day
815
+ @post = Post.new
816
+ @post.written_on = Date.new(2004, 6, 15)
817
+
818
+ expected = "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n"
819
+
820
+ expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n}
821
+ expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n}
822
+ expected << "</select>\n"
823
+
824
+ expected << %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
825
+ expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n}
826
+ expected << "</select>\n"
827
+
828
+ assert_equal expected, date_select("post", "written_on", :order => [ :month, :year ])
829
+ end
830
+
789
831
  def test_date_select_within_fields_for
790
832
  @post = Post.new
791
833
  @post.written_on = Date.new(2004, 6, 15)
@@ -1319,4 +1361,78 @@ class DateHelperTest < Test::Unit::TestCase
1319
1361
 
1320
1362
  assert_equal expected, datetime_select("post", "updated_at", :order => [:day, :month])
1321
1363
  end
1364
+
1365
+ def test_datetime_select_with_default_value_as_time
1366
+ @post = Post.new
1367
+ @post.updated_at = nil
1368
+
1369
+ expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}
1370
+ 2001.upto(2011) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2006}>#{i}</option>\n) }
1371
+ expected << "</select>\n"
1372
+ expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n}
1373
+ 1.upto(12) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 9}>#{Date::MONTHNAMES[i]}</option>\n) }
1374
+ expected << "</select>\n"
1375
+ expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n}
1376
+ 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 19}>#{i}</option>\n) }
1377
+ expected << "</select>\n"
1378
+
1379
+ expected << " &mdash; "
1380
+
1381
+ expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n}
1382
+ 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) }
1383
+ expected << "</select>\n"
1384
+ expected << " : "
1385
+ expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n}
1386
+ 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) }
1387
+ expected << "</select>\n"
1388
+
1389
+ assert_equal expected, datetime_select("post", "updated_at", :default => Time.local(2006, 9, 19, 15, 16, 35))
1390
+ end
1391
+
1392
+ def test_include_blank_overrides_default_option
1393
+ @post = Post.new
1394
+ @post.updated_at = nil
1395
+
1396
+ expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}
1397
+ expected << %(<option value=""></option>\n)
1398
+ 2002.upto(2012) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
1399
+ expected << "</select>\n"
1400
+ expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n}
1401
+ expected << %(<option value=""></option>\n)
1402
+ 1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) }
1403
+ expected << "</select>\n"
1404
+ expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n}
1405
+ expected << %(<option value=""></option>\n)
1406
+ 1.upto(31) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
1407
+ expected << "</select>\n"
1408
+
1409
+ assert_equal expected, date_select("post", "updated_at", :default => Time.local(2006, 9, 19, 15, 16, 35), :include_blank => true)
1410
+ end
1411
+
1412
+ def test_datetime_select_with_default_value_as_hash
1413
+ @post = Post.new
1414
+ @post.updated_at = nil
1415
+
1416
+ expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}
1417
+ (Time.now.year - 5).upto(Time.now.year + 5) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == Time.now.year}>#{i}</option>\n) }
1418
+ expected << "</select>\n"
1419
+ expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n}
1420
+ 1.upto(12) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 10}>#{Date::MONTHNAMES[i]}</option>\n) }
1421
+ expected << "</select>\n"
1422
+ expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n}
1423
+ 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == Time.now.day}>#{i}</option>\n) }
1424
+ expected << "</select>\n"
1425
+
1426
+ expected << " &mdash; "
1427
+
1428
+ expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n}
1429
+ 0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 9}>#{leading_zero_on_single_digits(i)}</option>\n) }
1430
+ expected << "</select>\n"
1431
+ expected << " : "
1432
+ expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n}
1433
+ 0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 42}>#{leading_zero_on_single_digits(i)}</option>\n) }
1434
+ expected << "</select>\n"
1435
+
1436
+ assert_equal expected, datetime_select("post", "updated_at", :default => { :month => 10, :minute => 42, :hour => 9 })
1437
+ end
1322
1438
  end