actionpack 2.2.3 → 2.3.2

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 (264) hide show
  1. data/CHANGELOG +433 -375
  2. data/MIT-LICENSE +1 -1
  3. data/README +21 -75
  4. data/Rakefile +1 -1
  5. data/lib/action_controller.rb +80 -43
  6. data/lib/action_controller/assertions/model_assertions.rb +1 -0
  7. data/lib/action_controller/assertions/response_assertions.rb +43 -16
  8. data/lib/action_controller/assertions/routing_assertions.rb +1 -1
  9. data/lib/action_controller/assertions/selector_assertions.rb +17 -12
  10. data/lib/action_controller/assertions/tag_assertions.rb +1 -4
  11. data/lib/action_controller/base.rb +153 -82
  12. data/lib/action_controller/benchmarking.rb +9 -9
  13. data/lib/action_controller/caching.rb +9 -11
  14. data/lib/action_controller/caching/actions.rb +11 -18
  15. data/lib/action_controller/caching/fragments.rb +28 -20
  16. data/lib/action_controller/caching/pages.rb +13 -15
  17. data/lib/action_controller/caching/sweeping.rb +2 -2
  18. data/lib/action_controller/cgi_ext.rb +0 -1
  19. data/lib/action_controller/cgi_ext/cookie.rb +2 -0
  20. data/lib/action_controller/cgi_process.rb +54 -162
  21. data/lib/action_controller/cookies.rb +13 -25
  22. data/lib/action_controller/dispatcher.rb +43 -122
  23. data/lib/action_controller/failsafe.rb +52 -0
  24. data/lib/action_controller/flash.rb +38 -47
  25. data/lib/action_controller/helpers.rb +13 -9
  26. data/lib/action_controller/http_authentication.rb +203 -23
  27. data/lib/action_controller/integration.rb +126 -70
  28. data/lib/action_controller/layout.rb +36 -39
  29. data/lib/action_controller/middleware_stack.rb +119 -0
  30. data/lib/action_controller/middlewares.rb +13 -0
  31. data/lib/action_controller/mime_responds.rb +19 -4
  32. data/lib/action_controller/mime_type.rb +8 -0
  33. data/lib/action_controller/params_parser.rb +71 -0
  34. data/lib/action_controller/performance_test.rb +0 -1
  35. data/lib/action_controller/polymorphic_routes.rb +36 -30
  36. data/lib/action_controller/reloader.rb +14 -0
  37. data/lib/action_controller/request.rb +107 -499
  38. data/lib/action_controller/request_forgery_protection.rb +7 -39
  39. data/lib/action_controller/rescue.rb +55 -35
  40. data/lib/action_controller/resources.rb +34 -31
  41. data/lib/action_controller/response.rb +99 -57
  42. data/lib/action_controller/rewindable_input.rb +28 -0
  43. data/lib/action_controller/routing.rb +7 -7
  44. data/lib/action_controller/routing/builder.rb +4 -1
  45. data/lib/action_controller/routing/optimisations.rb +1 -1
  46. data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
  47. data/lib/action_controller/routing/route.rb +15 -5
  48. data/lib/action_controller/routing/route_set.rb +82 -35
  49. data/lib/action_controller/routing/segments.rb +35 -0
  50. data/lib/action_controller/session/abstract_store.rb +181 -0
  51. data/lib/action_controller/session/cookie_store.rb +197 -175
  52. data/lib/action_controller/session/mem_cache_store.rb +36 -83
  53. data/lib/action_controller/session_management.rb +26 -134
  54. data/lib/action_controller/streaming.rb +24 -7
  55. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  56. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  57. data/lib/action_controller/test_case.rb +87 -30
  58. data/lib/action_controller/test_process.rb +145 -104
  59. data/lib/action_controller/uploaded_file.rb +44 -0
  60. data/lib/action_controller/url_rewriter.rb +3 -6
  61. data/lib/action_controller/vendor/html-scanner.rb +16 -0
  62. data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
  63. data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
  64. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
  65. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
  66. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
  67. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
  68. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
  69. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
  73. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
  74. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
  75. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
  76. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
  77. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
  78. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
  79. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
  80. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
  81. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
  82. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
  83. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
  84. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
  85. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
  86. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
  87. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
  93. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
  94. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
  95. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
  96. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
  97. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
  98. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
  99. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
  100. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
  101. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
  102. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
  103. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
  104. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
  105. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
  106. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
  107. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
  108. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
  109. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
  110. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
  111. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
  112. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
  113. data/lib/action_controller/verification.rb +1 -1
  114. data/lib/action_pack.rb +1 -1
  115. data/lib/action_pack/version.rb +2 -2
  116. data/lib/action_view.rb +22 -17
  117. data/lib/action_view/base.rb +53 -79
  118. data/lib/action_view/erb/util.rb +38 -0
  119. data/lib/action_view/helpers.rb +24 -5
  120. data/lib/action_view/helpers/active_record_helper.rb +2 -2
  121. data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
  122. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  123. data/lib/action_view/helpers/benchmark_helper.rb +26 -5
  124. data/lib/action_view/helpers/date_helper.rb +82 -7
  125. data/lib/action_view/helpers/form_helper.rb +295 -64
  126. data/lib/action_view/helpers/form_options_helper.rb +160 -18
  127. data/lib/action_view/helpers/form_tag_helper.rb +2 -2
  128. data/lib/action_view/helpers/number_helper.rb +31 -18
  129. data/lib/action_view/helpers/prototype_helper.rb +2 -12
  130. data/lib/action_view/helpers/sanitize_helper.rb +0 -10
  131. data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
  132. data/lib/action_view/helpers/tag_helper.rb +3 -4
  133. data/lib/action_view/helpers/text_helper.rb +99 -122
  134. data/lib/action_view/helpers/translation_helper.rb +19 -1
  135. data/lib/action_view/helpers/url_helper.rb +25 -2
  136. data/lib/action_view/inline_template.rb +1 -1
  137. data/lib/action_view/locale/en.yml +19 -1
  138. data/lib/action_view/partials.rb +46 -9
  139. data/lib/action_view/paths.rb +28 -84
  140. data/lib/action_view/reloadable_template.rb +117 -0
  141. data/lib/action_view/renderable.rb +28 -35
  142. data/lib/action_view/renderable_partial.rb +3 -4
  143. data/lib/action_view/template.rb +172 -31
  144. data/lib/action_view/template_error.rb +8 -9
  145. data/lib/action_view/template_handler.rb +1 -1
  146. data/lib/action_view/template_handlers.rb +9 -6
  147. data/lib/action_view/template_handlers/erb.rb +2 -39
  148. data/lib/action_view/template_handlers/rjs.rb +1 -0
  149. data/lib/action_view/test_case.rb +27 -1
  150. data/test/abstract_unit.rb +23 -17
  151. data/test/active_record_unit.rb +5 -4
  152. data/test/activerecord/active_record_store_test.rb +139 -106
  153. data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
  154. data/test/controller/action_pack_assertions_test.rb +25 -23
  155. data/test/controller/addresses_render_test.rb +3 -6
  156. data/test/controller/assert_select_test.rb +83 -70
  157. data/test/controller/base_test.rb +11 -13
  158. data/test/controller/benchmark_test.rb +3 -3
  159. data/test/controller/caching_test.rb +34 -24
  160. data/test/controller/capture_test.rb +3 -6
  161. data/test/controller/content_type_test.rb +3 -6
  162. data/test/controller/cookie_test.rb +31 -66
  163. data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
  164. data/test/controller/dispatcher_test.rb +23 -28
  165. data/test/controller/fake_models.rb +8 -0
  166. data/test/controller/filters_test.rb +6 -2
  167. data/test/controller/flash_test.rb +2 -6
  168. data/test/controller/helper_test.rb +15 -1
  169. data/test/controller/html-scanner/document_test.rb +1 -1
  170. data/test/controller/html-scanner/sanitizer_test.rb +1 -1
  171. data/test/controller/http_basic_authentication_test.rb +88 -0
  172. data/test/controller/http_digest_authentication_test.rb +178 -0
  173. data/test/controller/integration_test.rb +56 -52
  174. data/test/controller/layout_test.rb +46 -44
  175. data/test/controller/middleware_stack_test.rb +90 -0
  176. data/test/controller/mime_responds_test.rb +7 -11
  177. data/test/controller/mime_type_test.rb +9 -0
  178. data/test/controller/polymorphic_routes_test.rb +235 -151
  179. data/test/controller/rack_test.rb +52 -81
  180. data/test/controller/redirect_test.rb +6 -14
  181. data/test/controller/render_test.rb +273 -60
  182. data/test/controller/request/json_params_parsing_test.rb +45 -0
  183. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  184. data/test/controller/request/query_string_parsing_test.rb +120 -0
  185. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  186. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  187. data/test/controller/request_forgery_protection_test.rb +17 -98
  188. data/test/controller/request_test.rb +45 -530
  189. data/test/controller/rescue_test.rb +45 -22
  190. data/test/controller/resources_test.rb +112 -37
  191. data/test/controller/routing_test.rb +1442 -1384
  192. data/test/controller/selector_test.rb +3 -3
  193. data/test/controller/send_file_test.rb +30 -3
  194. data/test/controller/session/cookie_store_test.rb +169 -240
  195. data/test/controller/session/mem_cache_store_test.rb +94 -148
  196. data/test/controller/session/test_session_test.rb +58 -0
  197. data/test/controller/test_test.rb +32 -13
  198. data/test/controller/url_rewriter_test.rb +54 -4
  199. data/test/controller/verification_test.rb +1 -1
  200. data/test/controller/view_paths_test.rb +15 -15
  201. data/test/controller/webservice_test.rb +178 -147
  202. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  203. data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
  204. data/test/fixtures/layouts/default_html.html.erb +1 -0
  205. data/test/fixtures/layouts/xhr.html.erb +2 -0
  206. data/test/fixtures/multipart/empty +10 -0
  207. data/test/fixtures/multipart/hello.txt +1 -0
  208. data/test/fixtures/multipart/none +9 -0
  209. data/test/fixtures/public/500.da.html +1 -0
  210. data/test/fixtures/quiz/questions/_question.html.erb +1 -0
  211. data/test/fixtures/replies.yml +1 -1
  212. data/test/fixtures/test/_one.html.erb +1 -0
  213. data/test/fixtures/test/_two.html.erb +1 -0
  214. data/test/fixtures/test/dont_pick_me +1 -0
  215. data/test/fixtures/test/hello.builder +1 -1
  216. data/test/fixtures/test/hello_world.da.html.erb +1 -0
  217. data/test/fixtures/test/hello_world.erb~ +1 -0
  218. data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
  219. data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
  220. data/test/fixtures/test/malformed/malformed.erb~ +1 -0
  221. data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
  222. data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
  223. data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
  224. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
  225. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
  226. data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
  227. data/test/fixtures/test/utf8.html.erb +2 -0
  228. data/test/template/active_record_helper_i18n_test.rb +31 -33
  229. data/test/template/active_record_helper_test.rb +34 -0
  230. data/test/template/asset_tag_helper_test.rb +52 -14
  231. data/test/template/atom_feed_helper_test.rb +3 -5
  232. data/test/template/benchmark_helper_test.rb +50 -24
  233. data/test/template/compiled_templates_test.rb +177 -33
  234. data/test/template/date_helper_i18n_test.rb +88 -81
  235. data/test/template/date_helper_test.rb +427 -43
  236. data/test/template/form_helper_test.rb +243 -44
  237. data/test/template/form_options_helper_test.rb +631 -565
  238. data/test/template/form_tag_helper_test.rb +9 -2
  239. data/test/template/javascript_helper_test.rb +0 -5
  240. data/test/template/number_helper_i18n_test.rb +60 -48
  241. data/test/template/number_helper_test.rb +1 -0
  242. data/test/template/render_test.rb +117 -35
  243. data/test/template/test_test.rb +4 -6
  244. data/test/template/text_helper_test.rb +129 -50
  245. data/test/template/translation_helper_test.rb +23 -19
  246. data/test/template/url_helper_test.rb +35 -2
  247. data/test/view/test_case_test.rb +8 -0
  248. metadata +197 -23
  249. data/lib/action_controller/assertions.rb +0 -69
  250. data/lib/action_controller/caching/sql_cache.rb +0 -18
  251. data/lib/action_controller/cgi_ext/session.rb +0 -53
  252. data/lib/action_controller/components.rb +0 -169
  253. data/lib/action_controller/rack_process.rb +0 -297
  254. data/lib/action_controller/request_profiler.rb +0 -169
  255. data/lib/action_controller/session/active_record_store.rb +0 -340
  256. data/lib/action_controller/session/drb_server.rb +0 -32
  257. data/lib/action_controller/session/drb_store.rb +0 -35
  258. data/test/controller/cgi_test.rb +0 -269
  259. data/test/controller/components_test.rb +0 -156
  260. data/test/controller/http_authentication_test.rb +0 -54
  261. data/test/controller/integration_upload_test.rb +0 -43
  262. data/test/controller/session_fixation_test.rb +0 -89
  263. data/test/controller/session_management_test.rb +0 -178
  264. data/test/fixtures/test/hello_world.js +0 -1
@@ -1,685 +1,751 @@
1
1
  require 'abstract_unit'
2
+ require 'tzinfo'
2
3
 
3
4
  TZInfo::Timezone.cattr_reader :loaded_zones
4
5
 
5
- uses_mocha "FormOptionsHelperTest" do
6
- class FormOptionsHelperTest < ActionView::TestCase
7
- tests ActionView::Helpers::FormOptionsHelper
6
+ class FormOptionsHelperTest < ActionView::TestCase
7
+ tests ActionView::Helpers::FormOptionsHelper
8
8
 
9
- silence_warnings do
10
- Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
11
- Continent = Struct.new('Continent', :continent_name, :countries)
12
- Country = Struct.new('Country', :country_id, :country_name)
13
- Firm = Struct.new('Firm', :time_zone)
14
- Album = Struct.new('Album', :id, :title, :genre)
15
- end
9
+ silence_warnings do
10
+ Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
11
+ Continent = Struct.new('Continent', :continent_name, :countries)
12
+ Country = Struct.new('Country', :country_id, :country_name)
13
+ Firm = Struct.new('Firm', :time_zone)
14
+ Album = Struct.new('Album', :id, :title, :genre)
15
+ end
16
16
 
17
- def setup
18
- @fake_timezones = %w(A B C D E).inject([]) do |zones, id|
19
- tz = TZInfo::Timezone.loaded_zones[id] = stub(:name => id, :to_s => id)
20
- ActiveSupport::TimeZone.stubs(:[]).with(id).returns(tz)
21
- zones << tz
22
- end
23
- ActiveSupport::TimeZone.stubs(:all).returns(@fake_timezones)
17
+ def setup
18
+ @fake_timezones = %w(A B C D E).inject([]) do |zones, id|
19
+ tz = TZInfo::Timezone.loaded_zones[id] = stub(:name => id, :to_s => id)
20
+ ActiveSupport::TimeZone.stubs(:[]).with(id).returns(tz)
21
+ zones << tz
24
22
  end
23
+ ActiveSupport::TimeZone.stubs(:all).returns(@fake_timezones)
24
+ end
25
25
 
26
- def test_collection_options
27
- @posts = [
28
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
29
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
30
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
31
- ]
26
+ def test_collection_options
27
+ assert_dom_equal(
28
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
29
+ options_from_collection_for_select(dummy_posts, "author_name", "title")
30
+ )
31
+ end
32
32
 
33
+
34
+ def test_collection_options_with_preselected_value
35
+ assert_dom_equal(
36
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
37
+ options_from_collection_for_select(dummy_posts, "author_name", "title", "Babe")
38
+ )
39
+ end
40
+
41
+ def test_collection_options_with_preselected_value_array
33
42
  assert_dom_equal(
34
- "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
35
- options_from_collection_for_select(@posts, "author_name", "title")
43
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
44
+ options_from_collection_for_select(dummy_posts, "author_name", "title", [ "Babe", "Cabe" ])
36
45
  )
37
- end
46
+ end
38
47
 
48
+ def test_collection_options_with_proc_for_selected
49
+ assert_dom_equal(
50
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
51
+ options_from_collection_for_select(dummy_posts, "author_name", "title", lambda{|p| p.author_name == 'Babe' })
52
+ )
53
+ end
39
54
 
40
- def test_collection_options_with_preselected_value
41
- @posts = [
42
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
43
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
44
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
45
- ]
55
+ def test_collection_options_with_disabled_value
56
+ assert_dom_equal(
57
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
58
+ options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => "Babe")
59
+ )
60
+ end
46
61
 
47
- assert_dom_equal(
48
- "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
49
- options_from_collection_for_select(@posts, "author_name", "title", "Babe")
50
- )
51
- end
62
+ def test_collection_options_with_disabled_array
63
+ assert_dom_equal(
64
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
65
+ options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => [ "Babe", "Cabe" ])
66
+ )
67
+ end
52
68
 
53
- def test_collection_options_with_preselected_value_array
54
- @posts = [
55
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
56
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
57
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
58
- ]
59
-
60
- assert_dom_equal(
61
- "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
62
- options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ])
63
- )
64
- end
69
+ def test_collection_options_with_preselected_and_disabled_value
70
+ assert_dom_equal(
71
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
72
+ options_from_collection_for_select(dummy_posts, "author_name", "title", :selected => "Cabe", :disabled => "Babe")
73
+ )
74
+ end
65
75
 
66
- def test_array_options_for_select
67
- assert_dom_equal(
68
- "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>",
69
- options_for_select([ "<Denmark>", "USA", "Sweden" ])
70
- )
71
- end
76
+ def test_collection_options_with_proc_for_disabled
77
+ assert_dom_equal(
78
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
79
+ options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| %w(Babe Cabe).include? p.author_name })
80
+ )
81
+ end
82
+
83
+ def test_array_options_for_select
84
+ assert_dom_equal(
85
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>",
86
+ options_for_select([ "<Denmark>", "USA", "Sweden" ])
87
+ )
88
+ end
72
89
 
73
- def test_array_options_for_select_with_selection
90
+ def test_array_options_for_select_with_selection
91
+ assert_dom_equal(
92
+ "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>",
93
+ options_for_select([ "Denmark", "<USA>", "Sweden" ], "<USA>")
94
+ )
95
+ end
96
+
97
+ def test_array_options_for_select_with_selection_array
74
98
  assert_dom_equal(
75
- "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>",
76
- options_for_select([ "Denmark", "<USA>", "Sweden" ], "<USA>")
99
+ "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\" selected=\"selected\">Sweden</option>",
100
+ options_for_select([ "Denmark", "<USA>", "Sweden" ], [ "<USA>", "Sweden" ])
77
101
  )
78
- end
102
+ end
79
103
 
80
- def test_array_options_for_select_with_selection_array
81
- assert_dom_equal(
82
- "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\" selected=\"selected\">Sweden</option>",
83
- options_for_select([ "Denmark", "<USA>", "Sweden" ], [ "<USA>", "Sweden" ])
84
- )
85
- end
104
+ def test_array_options_for_select_with_disabled_value
105
+ assert_dom_equal(
106
+ "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" disabled=\"disabled\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>",
107
+ options_for_select([ "Denmark", "<USA>", "Sweden" ], :disabled => "<USA>")
108
+ )
109
+ end
86
110
 
87
- def test_array_options_for_string_include_in_other_string_bug_fix
88
- assert_dom_equal(
89
- "<option value=\"ruby\">ruby</option>\n<option value=\"rubyonrails\" selected=\"selected\">rubyonrails</option>",
90
- options_for_select([ "ruby", "rubyonrails" ], "rubyonrails")
91
- )
92
- assert_dom_equal(
93
- "<option value=\"ruby\" selected=\"selected\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>",
94
- options_for_select([ "ruby", "rubyonrails" ], "ruby")
95
- )
96
- assert_dom_equal(
97
- %(<option value="ruby" selected="selected">ruby</option>\n<option value="rubyonrails">rubyonrails</option>\n<option value=""></option>),
98
- options_for_select([ "ruby", "rubyonrails", nil ], "ruby")
99
- )
100
- end
111
+ def test_array_options_for_select_with_disabled_array
112
+ assert_dom_equal(
113
+ "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" disabled=\"disabled\">&lt;USA&gt;</option>\n<option value=\"Sweden\" disabled=\"disabled\">Sweden</option>",
114
+ options_for_select([ "Denmark", "<USA>", "Sweden" ], :disabled => ["<USA>", "Sweden"])
115
+ )
116
+ end
101
117
 
102
- def test_hash_options_for_select
103
- assert_dom_equal(
104
- "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
105
- options_for_select("$" => "Dollar", "<DKR>" => "<Kroner>").split("\n").sort.join("\n")
106
- )
107
- assert_dom_equal(
108
- "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
109
- options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar").split("\n").sort.join("\n")
110
- )
111
- assert_dom_equal(
112
- "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
113
- options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ]).split("\n").sort.join("\n")
114
- )
115
- end
118
+ def test_array_options_for_select_with_selection_and_disabled_value
119
+ assert_dom_equal(
120
+ "<option value=\"Denmark\" selected=\"selected\">Denmark</option>\n<option value=\"&lt;USA&gt;\" disabled=\"disabled\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>",
121
+ options_for_select([ "Denmark", "<USA>", "Sweden" ], :selected => "Denmark", :disabled => "<USA>")
122
+ )
123
+ end
116
124
 
117
- def test_ducktyped_options_for_select
118
- quack = Struct.new(:first, :last)
125
+ def test_array_options_for_string_include_in_other_string_bug_fix
119
126
  assert_dom_equal(
120
- "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
121
- options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")])
127
+ "<option value=\"ruby\">ruby</option>\n<option value=\"rubyonrails\" selected=\"selected\">rubyonrails</option>",
128
+ options_for_select([ "ruby", "rubyonrails" ], "rubyonrails")
122
129
  )
123
130
  assert_dom_equal(
124
- "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
125
- options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], "Dollar")
131
+ "<option value=\"ruby\" selected=\"selected\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>",
132
+ options_for_select([ "ruby", "rubyonrails" ], "ruby")
126
133
  )
127
134
  assert_dom_equal(
128
- "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
129
- options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], ["Dollar", "<Kroner>"])
135
+ %(<option value="ruby" selected="selected">ruby</option>\n<option value="rubyonrails">rubyonrails</option>\n<option value=""></option>),
136
+ options_for_select([ "ruby", "rubyonrails", nil ], "ruby")
130
137
  )
131
- end
132
-
133
- def test_option_groups_from_collection_for_select
134
- @continents = [
135
- Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
136
- Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
137
- ]
138
+ end
138
139
 
139
- assert_dom_equal(
140
- "<optgroup label=\"&lt;Africa&gt;\"><option value=\"&lt;sa&gt;\">&lt;South Africa&gt;</option>\n<option value=\"so\">Somalia</option></optgroup><optgroup label=\"Europe\"><option value=\"dk\" selected=\"selected\">Denmark</option>\n<option value=\"ie\">Ireland</option></optgroup>",
141
- option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk")
142
- )
143
- end
140
+ def test_hash_options_for_select
141
+ assert_dom_equal(
142
+ "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
143
+ options_for_select("$" => "Dollar", "<DKR>" => "<Kroner>").split("\n").sort.join("\n")
144
+ )
145
+ assert_dom_equal(
146
+ "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
147
+ options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar").split("\n").sort.join("\n")
148
+ )
149
+ assert_dom_equal(
150
+ "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
151
+ options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ]).split("\n").sort.join("\n")
152
+ )
153
+ end
144
154
 
145
- def test_time_zone_options_no_parms
146
- opts = time_zone_options_for_select
147
- assert_dom_equal "<option value=\"A\">A</option>\n" +
148
- "<option value=\"B\">B</option>\n" +
149
- "<option value=\"C\">C</option>\n" +
150
- "<option value=\"D\">D</option>\n" +
151
- "<option value=\"E\">E</option>",
152
- opts
153
- end
155
+ def test_ducktyped_options_for_select
156
+ quack = Struct.new(:first, :last)
157
+ assert_dom_equal(
158
+ "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
159
+ options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")])
160
+ )
161
+ assert_dom_equal(
162
+ "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
163
+ options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], "Dollar")
164
+ )
165
+ assert_dom_equal(
166
+ "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
167
+ options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], ["Dollar", "<Kroner>"])
168
+ )
169
+ end
154
170
 
155
- def test_time_zone_options_with_selected
156
- opts = time_zone_options_for_select( "D" )
157
- assert_dom_equal "<option value=\"A\">A</option>\n" +
158
- "<option value=\"B\">B</option>\n" +
159
- "<option value=\"C\">C</option>\n" +
160
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
161
- "<option value=\"E\">E</option>",
162
- opts
163
- end
171
+ def test_option_groups_from_collection_for_select
172
+ @continents = [
173
+ Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
174
+ Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
175
+ ]
164
176
 
165
- def test_time_zone_options_with_unknown_selected
166
- opts = time_zone_options_for_select( "K" )
167
- assert_dom_equal "<option value=\"A\">A</option>\n" +
168
- "<option value=\"B\">B</option>\n" +
169
- "<option value=\"C\">C</option>\n" +
170
- "<option value=\"D\">D</option>\n" +
171
- "<option value=\"E\">E</option>",
172
- opts
173
- end
177
+ assert_dom_equal(
178
+ "<optgroup label=\"&lt;Africa&gt;\"><option value=\"&lt;sa&gt;\">&lt;South Africa&gt;</option>\n<option value=\"so\">Somalia</option></optgroup><optgroup label=\"Europe\"><option value=\"dk\" selected=\"selected\">Denmark</option>\n<option value=\"ie\">Ireland</option></optgroup>",
179
+ option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk")
180
+ )
181
+ end
174
182
 
175
- def test_time_zone_options_with_priority_zones
176
- zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
177
- opts = time_zone_options_for_select( nil, zones )
178
- assert_dom_equal "<option value=\"B\">B</option>\n" +
179
- "<option value=\"E\">E</option>" +
180
- "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
181
- "<option value=\"A\">A</option>\n" +
182
- "<option value=\"C\">C</option>\n" +
183
- "<option value=\"D\">D</option>",
184
- opts
185
- end
183
+ def test_grouped_options_for_select_with_array
184
+ assert_dom_equal(
185
+ "<optgroup label=\"North America\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>",
186
+ grouped_options_for_select([
187
+ ["North America",
188
+ [['United States','US'],"Canada"]],
189
+ ["Europe",
190
+ [["Great Britain","GB"], "Germany"]]
191
+ ])
192
+ )
193
+ end
186
194
 
187
- def test_time_zone_options_with_selected_priority_zones
188
- zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
189
- opts = time_zone_options_for_select( "E", zones )
190
- assert_dom_equal "<option value=\"B\">B</option>\n" +
191
- "<option value=\"E\" selected=\"selected\">E</option>" +
192
- "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
193
- "<option value=\"A\">A</option>\n" +
194
- "<option value=\"C\">C</option>\n" +
195
- "<option value=\"D\">D</option>",
196
- opts
197
- end
195
+ def test_grouped_options_for_select_with_selected_and_prompt
196
+ assert_dom_equal(
197
+ "<option value=\"\">Choose a product...</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option selected=\"selected\" value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
198
+ grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], "Cowboy Hat", "Choose a product...")
199
+ )
200
+ end
198
201
 
199
- def test_time_zone_options_with_unselected_priority_zones
200
- zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
201
- opts = time_zone_options_for_select( "C", zones )
202
- assert_dom_equal "<option value=\"B\">B</option>\n" +
203
- "<option value=\"E\">E</option>" +
204
- "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
205
- "<option value=\"A\">A</option>\n" +
206
- "<option value=\"C\" selected=\"selected\">C</option>\n" +
207
- "<option value=\"D\">D</option>",
208
- opts
209
- end
202
+ def test_optgroups_with_with_options_with_hash
203
+ assert_dom_equal(
204
+ "<optgroup label=\"Europe\"><option value=\"Denmark\">Denmark</option>\n<option value=\"Germany\">Germany</option></optgroup><optgroup label=\"North America\"><option value=\"United States\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup>",
205
+ grouped_options_for_select({'North America' => ['United States','Canada'], 'Europe' => ['Denmark','Germany']})
206
+ )
207
+ end
210
208
 
211
- def test_select
212
- @post = Post.new
213
- @post.category = "<mus>"
214
- assert_dom_equal(
215
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
216
- select("post", "category", %w( abe <mus> hest))
217
- )
218
- end
209
+ def test_time_zone_options_no_parms
210
+ opts = time_zone_options_for_select
211
+ assert_dom_equal "<option value=\"A\">A</option>\n" +
212
+ "<option value=\"B\">B</option>\n" +
213
+ "<option value=\"C\">C</option>\n" +
214
+ "<option value=\"D\">D</option>\n" +
215
+ "<option value=\"E\">E</option>",
216
+ opts
217
+ end
219
218
 
220
- def test_select_under_fields_for
221
- @post = Post.new
222
- @post.category = "<mus>"
219
+ def test_time_zone_options_with_selected
220
+ opts = time_zone_options_for_select( "D" )
221
+ assert_dom_equal "<option value=\"A\">A</option>\n" +
222
+ "<option value=\"B\">B</option>\n" +
223
+ "<option value=\"C\">C</option>\n" +
224
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
225
+ "<option value=\"E\">E</option>",
226
+ opts
227
+ end
223
228
 
224
- fields_for :post, @post do |f|
225
- concat f.select(:category, %w( abe <mus> hest))
226
- end
227
-
228
- assert_dom_equal(
229
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
230
- output_buffer
231
- )
232
- end
229
+ def test_time_zone_options_with_unknown_selected
230
+ opts = time_zone_options_for_select( "K" )
231
+ assert_dom_equal "<option value=\"A\">A</option>\n" +
232
+ "<option value=\"B\">B</option>\n" +
233
+ "<option value=\"C\">C</option>\n" +
234
+ "<option value=\"D\">D</option>\n" +
235
+ "<option value=\"E\">E</option>",
236
+ opts
237
+ end
233
238
 
234
- def test_select_under_fields_for_with_index
235
- @post = Post.new
236
- @post.category = "<mus>"
239
+ def test_time_zone_options_with_priority_zones
240
+ zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
241
+ opts = time_zone_options_for_select( nil, zones )
242
+ assert_dom_equal "<option value=\"B\">B</option>\n" +
243
+ "<option value=\"E\">E</option>" +
244
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
245
+ "<option value=\"A\">A</option>\n" +
246
+ "<option value=\"C\">C</option>\n" +
247
+ "<option value=\"D\">D</option>",
248
+ opts
249
+ end
237
250
 
238
- fields_for :post, @post, :index => 108 do |f|
239
- concat f.select(:category, %w( abe <mus> hest))
240
- end
251
+ def test_time_zone_options_with_selected_priority_zones
252
+ zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
253
+ opts = time_zone_options_for_select( "E", zones )
254
+ assert_dom_equal "<option value=\"B\">B</option>\n" +
255
+ "<option value=\"E\" selected=\"selected\">E</option>" +
256
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
257
+ "<option value=\"A\">A</option>\n" +
258
+ "<option value=\"C\">C</option>\n" +
259
+ "<option value=\"D\">D</option>",
260
+ opts
261
+ end
241
262
 
242
- assert_dom_equal(
243
- "<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
244
- output_buffer
245
- )
246
- end
263
+ def test_time_zone_options_with_unselected_priority_zones
264
+ zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
265
+ opts = time_zone_options_for_select( "C", zones )
266
+ assert_dom_equal "<option value=\"B\">B</option>\n" +
267
+ "<option value=\"E\">E</option>" +
268
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
269
+ "<option value=\"A\">A</option>\n" +
270
+ "<option value=\"C\" selected=\"selected\">C</option>\n" +
271
+ "<option value=\"D\">D</option>",
272
+ opts
273
+ end
247
274
 
248
- def test_select_under_fields_for_with_auto_index
249
- @post = Post.new
250
- @post.category = "<mus>"
251
- def @post.to_param; 108; end
275
+ def test_select
276
+ @post = Post.new
277
+ @post.category = "<mus>"
278
+ assert_dom_equal(
279
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
280
+ select("post", "category", %w( abe <mus> hest))
281
+ )
282
+ end
252
283
 
253
- fields_for "post[]", @post do |f|
254
- concat f.select(:category, %w( abe <mus> hest))
255
- end
284
+ def test_select_under_fields_for
285
+ @post = Post.new
286
+ @post.category = "<mus>"
256
287
 
257
- assert_dom_equal(
258
- "<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
259
- output_buffer
260
- )
288
+ fields_for :post, @post do |f|
289
+ concat f.select(:category, %w( abe <mus> hest))
261
290
  end
291
+
292
+ assert_dom_equal(
293
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
294
+ output_buffer
295
+ )
296
+ end
262
297
 
263
- def test_select_with_blank
264
- @post = Post.new
265
- @post.category = "<mus>"
266
- assert_dom_equal(
267
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
268
- select("post", "category", %w( abe <mus> hest), :include_blank => true)
269
- )
270
- end
298
+ def test_select_under_fields_for_with_index
299
+ @post = Post.new
300
+ @post.category = "<mus>"
271
301
 
272
- def test_select_with_blank_as_string
273
- @post = Post.new
274
- @post.category = "<mus>"
275
- assert_dom_equal(
276
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">None</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
277
- select("post", "category", %w( abe <mus> hest), :include_blank => 'None')
278
- )
302
+ fields_for :post, @post, :index => 108 do |f|
303
+ concat f.select(:category, %w( abe <mus> hest))
279
304
  end
280
305
 
281
- def test_select_with_default_prompt
282
- @post = Post.new
283
- @post.category = ""
284
- assert_dom_equal(
285
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
286
- select("post", "category", %w( abe <mus> hest), :prompt => true)
287
- )
288
- end
306
+ assert_dom_equal(
307
+ "<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
308
+ output_buffer
309
+ )
310
+ end
289
311
 
290
- def test_select_no_prompt_when_select_has_value
291
- @post = Post.new
292
- @post.category = "<mus>"
293
- assert_dom_equal(
294
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
295
- select("post", "category", %w( abe <mus> hest), :prompt => true)
296
- )
297
- end
312
+ def test_select_under_fields_for_with_auto_index
313
+ @post = Post.new
314
+ @post.category = "<mus>"
315
+ def @post.to_param; 108; end
298
316
 
299
- def test_select_with_given_prompt
300
- @post = Post.new
301
- @post.category = ""
302
- assert_dom_equal(
303
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">The prompt</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
304
- select("post", "category", %w( abe <mus> hest), :prompt => 'The prompt')
305
- )
317
+ fields_for "post[]", @post do |f|
318
+ concat f.select(:category, %w( abe <mus> hest))
306
319
  end
307
320
 
308
- def test_select_with_prompt_and_blank
309
- @post = Post.new
310
- @post.category = ""
311
- assert_dom_equal(
312
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
313
- select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true)
314
- )
315
- end
321
+ assert_dom_equal(
322
+ "<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
323
+ output_buffer
324
+ )
325
+ end
316
326
 
317
- def test_select_with_selected_value
318
- @post = Post.new
319
- @post.category = "<mus>"
320
- assert_dom_equal(
321
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" selected=\"selected\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
322
- select("post", "category", %w( abe <mus> hest ), :selected => 'abe')
323
- )
324
- end
327
+ def test_select_with_blank
328
+ @post = Post.new
329
+ @post.category = "<mus>"
330
+ assert_dom_equal(
331
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
332
+ select("post", "category", %w( abe <mus> hest), :include_blank => true)
333
+ )
334
+ end
335
+
336
+ def test_select_with_blank_as_string
337
+ @post = Post.new
338
+ @post.category = "<mus>"
339
+ assert_dom_equal(
340
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">None</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
341
+ select("post", "category", %w( abe <mus> hest), :include_blank => 'None')
342
+ )
343
+ end
344
+
345
+ def test_select_with_default_prompt
346
+ @post = Post.new
347
+ @post.category = ""
348
+ assert_dom_equal(
349
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
350
+ select("post", "category", %w( abe <mus> hest), :prompt => true)
351
+ )
352
+ end
353
+
354
+ def test_select_no_prompt_when_select_has_value
355
+ @post = Post.new
356
+ @post.category = "<mus>"
357
+ assert_dom_equal(
358
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
359
+ select("post", "category", %w( abe <mus> hest), :prompt => true)
360
+ )
361
+ end
362
+
363
+ def test_select_with_given_prompt
364
+ @post = Post.new
365
+ @post.category = ""
366
+ assert_dom_equal(
367
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">The prompt</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
368
+ select("post", "category", %w( abe <mus> hest), :prompt => 'The prompt')
369
+ )
370
+ end
371
+
372
+ def test_select_with_prompt_and_blank
373
+ @post = Post.new
374
+ @post.category = ""
375
+ assert_dom_equal(
376
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
377
+ select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true)
378
+ )
379
+ end
380
+
381
+ def test_select_with_selected_value
382
+ @post = Post.new
383
+ @post.category = "<mus>"
384
+ assert_dom_equal(
385
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" selected=\"selected\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
386
+ select("post", "category", %w( abe <mus> hest ), :selected => 'abe')
387
+ )
388
+ end
389
+
390
+ def test_select_with_index_option
391
+ @album = Album.new
392
+ @album.id = 1
325
393
 
326
- def test_select_with_index_option
327
- @album = Album.new
328
- @album.id = 1
329
-
330
- expected = "<select id=\"album__genre\" name=\"album[][genre]\"><option value=\"rap\">rap</option>\n<option value=\"rock\">rock</option>\n<option value=\"country\">country</option></select>"
394
+ expected = "<select id=\"album__genre\" name=\"album[][genre]\"><option value=\"rap\">rap</option>\n<option value=\"rock\">rock</option>\n<option value=\"country\">country</option></select>"
331
395
 
332
- assert_dom_equal(
333
- expected,
334
- select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
335
- )
336
- end
396
+ assert_dom_equal(
397
+ expected,
398
+ select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
399
+ )
400
+ end
337
401
 
338
- def test_select_with_selected_nil
339
- @post = Post.new
340
- @post.category = "<mus>"
341
- assert_dom_equal(
342
- "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
343
- select("post", "category", %w( abe <mus> hest ), :selected => nil)
344
- )
345
- end
402
+ def test_select_with_selected_nil
403
+ @post = Post.new
404
+ @post.category = "<mus>"
405
+ assert_dom_equal(
406
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
407
+ select("post", "category", %w( abe <mus> hest ), :selected => nil)
408
+ )
409
+ end
346
410
 
347
- def test_collection_select
348
- @posts = [
349
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
350
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
351
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
352
- ]
411
+ def test_select_with_disabled_value
412
+ @post = Post.new
413
+ @post.category = "<mus>"
414
+ assert_dom_equal(
415
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\" disabled=\"disabled\">hest</option></select>",
416
+ select("post", "category", %w( abe <mus> hest ), :disabled => 'hest')
417
+ )
418
+ end
353
419
 
354
- @post = Post.new
355
- @post.author_name = "Babe"
420
+ def test_select_with_disabled_array
421
+ @post = Post.new
422
+ @post.category = "<mus>"
423
+ assert_dom_equal(
424
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" disabled=\"disabled\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\" disabled=\"disabled\">hest</option></select>",
425
+ select("post", "category", %w( abe <mus> hest ), :disabled => ['hest', 'abe'])
426
+ )
427
+ end
356
428
 
357
- assert_dom_equal(
358
- "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
359
- collection_select("post", "author_name", @posts, "author_name", "author_name")
360
- )
361
- end
429
+ def test_collection_select
430
+ @post = Post.new
431
+ @post.author_name = "Babe"
362
432
 
363
- def test_collection_select_under_fields_for
364
- @posts = [
365
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
366
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
367
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
368
- ]
433
+ assert_dom_equal(
434
+ "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
435
+ collection_select("post", "author_name", dummy_posts, "author_name", "author_name")
436
+ )
437
+ end
369
438
 
370
- @post = Post.new
371
- @post.author_name = "Babe"
439
+ def test_collection_select_under_fields_for
440
+ @post = Post.new
441
+ @post.author_name = "Babe"
372
442
 
373
- fields_for :post, @post do |f|
374
- concat f.collection_select(:author_name, @posts, :author_name, :author_name)
375
- end
376
-
377
- assert_dom_equal(
378
- "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
379
- output_buffer
380
- )
443
+ fields_for :post, @post do |f|
444
+ concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
381
445
  end
446
+
447
+ assert_dom_equal(
448
+ "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
449
+ output_buffer
450
+ )
451
+ end
382
452
 
383
- def test_collection_select_under_fields_for_with_index
384
- @posts = [
385
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
386
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
387
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
388
- ]
453
+ def test_collection_select_under_fields_for_with_index
454
+ @post = Post.new
455
+ @post.author_name = "Babe"
456
+
457
+ fields_for :post, @post, :index => 815 do |f|
458
+ concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
459
+ end
389
460
 
390
- @post = Post.new
391
- @post.author_name = "Babe"
461
+ assert_dom_equal(
462
+ "<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
463
+ output_buffer
464
+ )
465
+ end
392
466
 
393
- fields_for :post, @post, :index => 815 do |f|
394
- concat f.collection_select(:author_name, @posts, :author_name, :author_name)
395
- end
467
+ def test_collection_select_under_fields_for_with_auto_index
468
+ @post = Post.new
469
+ @post.author_name = "Babe"
470
+ def @post.to_param; 815; end
396
471
 
397
- assert_dom_equal(
398
- "<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
399
- output_buffer
400
- )
472
+ fields_for "post[]", @post do |f|
473
+ concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
401
474
  end
402
475
 
403
- def test_collection_select_under_fields_for_with_auto_index
404
- @posts = [
405
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
406
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
407
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
408
- ]
476
+ assert_dom_equal(
477
+ "<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
478
+ output_buffer
479
+ )
480
+ end
409
481
 
410
- @post = Post.new
411
- @post.author_name = "Babe"
412
- def @post.to_param; 815; end
482
+ def test_collection_select_with_blank_and_style
483
+ @post = Post.new
484
+ @post.author_name = "Babe"
413
485
 
414
- fields_for "post[]", @post do |f|
415
- concat f.collection_select(:author_name, @posts, :author_name, :author_name)
416
- end
486
+ assert_dom_equal(
487
+ "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
488
+ collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
489
+ )
490
+ end
417
491
 
418
- assert_dom_equal(
419
- "<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
420
- output_buffer
421
- )
422
- end
492
+ def test_collection_select_with_blank_as_string_and_style
493
+ @post = Post.new
494
+ @post.author_name = "Babe"
423
495
 
424
- def test_collection_select_with_blank_and_style
425
- @posts = [
426
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
427
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
428
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
429
- ]
496
+ assert_dom_equal(
497
+ "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\">No Selection</option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
498
+ collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px")
499
+ )
500
+ end
430
501
 
431
- @post = Post.new
432
- @post.author_name = "Babe"
502
+ def test_collection_select_with_multiple_option_appends_array_brackets
503
+ @post = Post.new
504
+ @post.author_name = "Babe"
433
505
 
434
- assert_dom_equal(
435
- "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
436
- collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
437
- )
438
- end
506
+ expected = "<select id=\"post_author_name\" name=\"post[author_name][]\" multiple=\"multiple\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>"
439
507
 
440
- def test_collection_select_with_blank_as_string_and_style
441
- @posts = [
442
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
443
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
444
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
445
- ]
508
+ # Should suffix default name with [].
509
+ assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, :multiple => true)
446
510
 
447
- @post = Post.new
448
- @post.author_name = "Babe"
511
+ # Shouldn't suffix custom name with [].
512
+ assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true)
513
+ end
449
514
 
450
- assert_dom_equal(
451
- "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\">No Selection</option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
452
- collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px")
453
- )
454
- end
515
+ def test_collection_select_with_blank_and_selected
516
+ @post = Post.new
517
+ @post.author_name = "Babe"
455
518
 
456
- def test_collection_select_with_multiple_option_appends_array_brackets
457
- @posts = [
458
- Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
459
- Post.new("Babe went home", "Babe", "To a little house", "shh!"),
460
- Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
461
- ]
519
+ assert_dom_equal(
520
+ %{<select id="post_author_name" name="post[author_name]"><option value=""></option>\n<option value="&lt;Abe&gt;" selected="selected">&lt;Abe&gt;</option>\n<option value="Babe">Babe</option>\n<option value="Cabe">Cabe</option></select>},
521
+ collection_select("post", "author_name", dummy_posts, "author_name", "author_name", {:include_blank => true, :selected => "<Abe>"})
522
+ )
523
+ end
462
524
 
463
- @post = Post.new
464
- @post.author_name = "Babe"
525
+ def test_collection_select_with_disabled
526
+ @post = Post.new
527
+ @post.author_name = "Babe"
465
528
 
466
- expected = "<select id=\"post_author_name\" name=\"post[author_name][]\" multiple=\"multiple\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>"
529
+ assert_dom_equal(
530
+ "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe</option></select>",
531
+ collection_select("post", "author_name", dummy_posts, "author_name", "author_name", :disabled => 'Cabe')
532
+ )
533
+ end
467
534
 
468
- # Should suffix default name with [].
469
- assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, :multiple => true)
535
+ def test_time_zone_select
536
+ @firm = Firm.new("D")
537
+ html = time_zone_select( "firm", "time_zone" )
538
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
539
+ "<option value=\"A\">A</option>\n" +
540
+ "<option value=\"B\">B</option>\n" +
541
+ "<option value=\"C\">C</option>\n" +
542
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
543
+ "<option value=\"E\">E</option>" +
544
+ "</select>",
545
+ html
546
+ end
470
547
 
471
- # Shouldn't suffix custom name with [].
472
- assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true)
473
- end
548
+ def test_time_zone_select_under_fields_for
549
+ @firm = Firm.new("D")
474
550
 
475
- def test_time_zone_select
476
- @firm = Firm.new("D")
477
- html = time_zone_select( "firm", "time_zone" )
478
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
479
- "<option value=\"A\">A</option>\n" +
480
- "<option value=\"B\">B</option>\n" +
481
- "<option value=\"C\">C</option>\n" +
482
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
483
- "<option value=\"E\">E</option>" +
484
- "</select>",
485
- html
551
+ fields_for :firm, @firm do |f|
552
+ concat f.time_zone_select(:time_zone)
486
553
  end
554
+
555
+ assert_dom_equal(
556
+ "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
557
+ "<option value=\"A\">A</option>\n" +
558
+ "<option value=\"B\">B</option>\n" +
559
+ "<option value=\"C\">C</option>\n" +
560
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
561
+ "<option value=\"E\">E</option>" +
562
+ "</select>",
563
+ output_buffer
564
+ )
565
+ end
487
566
 
488
- def test_time_zone_select_under_fields_for
489
- @firm = Firm.new("D")
567
+ def test_time_zone_select_under_fields_for_with_index
568
+ @firm = Firm.new("D")
490
569
 
491
- fields_for :firm, @firm do |f|
492
- concat f.time_zone_select(:time_zone)
493
- end
494
-
495
- assert_dom_equal(
496
- "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
497
- "<option value=\"A\">A</option>\n" +
498
- "<option value=\"B\">B</option>\n" +
499
- "<option value=\"C\">C</option>\n" +
500
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
501
- "<option value=\"E\">E</option>" +
502
- "</select>",
503
- output_buffer
504
- )
570
+ fields_for :firm, @firm, :index => 305 do |f|
571
+ concat f.time_zone_select(:time_zone)
505
572
  end
506
573
 
507
- def test_time_zone_select_under_fields_for_with_index
508
- @firm = Firm.new("D")
574
+ assert_dom_equal(
575
+ "<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" +
576
+ "<option value=\"A\">A</option>\n" +
577
+ "<option value=\"B\">B</option>\n" +
578
+ "<option value=\"C\">C</option>\n" +
579
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
580
+ "<option value=\"E\">E</option>" +
581
+ "</select>",
582
+ output_buffer
583
+ )
584
+ end
509
585
 
510
- fields_for :firm, @firm, :index => 305 do |f|
511
- concat f.time_zone_select(:time_zone)
512
- end
586
+ def test_time_zone_select_under_fields_for_with_auto_index
587
+ @firm = Firm.new("D")
588
+ def @firm.to_param; 305; end
513
589
 
514
- assert_dom_equal(
515
- "<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" +
516
- "<option value=\"A\">A</option>\n" +
517
- "<option value=\"B\">B</option>\n" +
518
- "<option value=\"C\">C</option>\n" +
519
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
520
- "<option value=\"E\">E</option>" +
521
- "</select>",
522
- output_buffer
523
- )
590
+ fields_for "firm[]", @firm do |f|
591
+ concat f.time_zone_select(:time_zone)
524
592
  end
525
593
 
526
- def test_time_zone_select_under_fields_for_with_auto_index
527
- @firm = Firm.new("D")
528
- def @firm.to_param; 305; end
594
+ assert_dom_equal(
595
+ "<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" +
596
+ "<option value=\"A\">A</option>\n" +
597
+ "<option value=\"B\">B</option>\n" +
598
+ "<option value=\"C\">C</option>\n" +
599
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
600
+ "<option value=\"E\">E</option>" +
601
+ "</select>",
602
+ output_buffer
603
+ )
604
+ end
529
605
 
530
- fields_for "firm[]", @firm do |f|
531
- concat f.time_zone_select(:time_zone)
532
- end
606
+ def test_time_zone_select_with_blank
607
+ @firm = Firm.new("D")
608
+ html = time_zone_select("firm", "time_zone", nil, :include_blank => true)
609
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
610
+ "<option value=\"\"></option>\n" +
611
+ "<option value=\"A\">A</option>\n" +
612
+ "<option value=\"B\">B</option>\n" +
613
+ "<option value=\"C\">C</option>\n" +
614
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
615
+ "<option value=\"E\">E</option>" +
616
+ "</select>",
617
+ html
618
+ end
533
619
 
534
- assert_dom_equal(
535
- "<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" +
536
- "<option value=\"A\">A</option>\n" +
537
- "<option value=\"B\">B</option>\n" +
538
- "<option value=\"C\">C</option>\n" +
539
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
540
- "<option value=\"E\">E</option>" +
541
- "</select>",
542
- output_buffer
543
- )
544
- end
620
+ def test_time_zone_select_with_blank_as_string
621
+ @firm = Firm.new("D")
622
+ html = time_zone_select("firm", "time_zone", nil, :include_blank => 'No Zone')
623
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
624
+ "<option value=\"\">No Zone</option>\n" +
625
+ "<option value=\"A\">A</option>\n" +
626
+ "<option value=\"B\">B</option>\n" +
627
+ "<option value=\"C\">C</option>\n" +
628
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
629
+ "<option value=\"E\">E</option>" +
630
+ "</select>",
631
+ html
632
+ end
545
633
 
546
- def test_time_zone_select_with_blank
547
- @firm = Firm.new("D")
548
- html = time_zone_select("firm", "time_zone", nil, :include_blank => true)
549
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
550
- "<option value=\"\"></option>\n" +
551
- "<option value=\"A\">A</option>\n" +
552
- "<option value=\"B\">B</option>\n" +
553
- "<option value=\"C\">C</option>\n" +
554
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
555
- "<option value=\"E\">E</option>" +
556
- "</select>",
557
- html
558
- end
634
+ def test_time_zone_select_with_style
635
+ @firm = Firm.new("D")
636
+ html = time_zone_select("firm", "time_zone", nil, {},
637
+ "style" => "color: red")
638
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
639
+ "<option value=\"A\">A</option>\n" +
640
+ "<option value=\"B\">B</option>\n" +
641
+ "<option value=\"C\">C</option>\n" +
642
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
643
+ "<option value=\"E\">E</option>" +
644
+ "</select>",
645
+ html
646
+ assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {},
647
+ :style => "color: red")
648
+ end
559
649
 
560
- def test_time_zone_select_with_blank_as_string
561
- @firm = Firm.new("D")
562
- html = time_zone_select("firm", "time_zone", nil, :include_blank => 'No Zone')
563
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
564
- "<option value=\"\">No Zone</option>\n" +
565
- "<option value=\"A\">A</option>\n" +
566
- "<option value=\"B\">B</option>\n" +
567
- "<option value=\"C\">C</option>\n" +
568
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
569
- "<option value=\"E\">E</option>" +
570
- "</select>",
571
- html
572
- end
650
+ def test_time_zone_select_with_blank_and_style
651
+ @firm = Firm.new("D")
652
+ html = time_zone_select("firm", "time_zone", nil,
653
+ { :include_blank => true }, "style" => "color: red")
654
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
655
+ "<option value=\"\"></option>\n" +
656
+ "<option value=\"A\">A</option>\n" +
657
+ "<option value=\"B\">B</option>\n" +
658
+ "<option value=\"C\">C</option>\n" +
659
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
660
+ "<option value=\"E\">E</option>" +
661
+ "</select>",
662
+ html
663
+ assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
664
+ { :include_blank => true }, :style => "color: red")
665
+ end
573
666
 
574
- def test_time_zone_select_with_style
575
- @firm = Firm.new("D")
576
- html = time_zone_select("firm", "time_zone", nil, {},
577
- "style" => "color: red")
578
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
579
- "<option value=\"A\">A</option>\n" +
580
- "<option value=\"B\">B</option>\n" +
581
- "<option value=\"C\">C</option>\n" +
582
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
583
- "<option value=\"E\">E</option>" +
584
- "</select>",
585
- html
586
- assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {},
587
- :style => "color: red")
588
- end
667
+ def test_time_zone_select_with_blank_as_string_and_style
668
+ @firm = Firm.new("D")
669
+ html = time_zone_select("firm", "time_zone", nil,
670
+ { :include_blank => 'No Zone' }, "style" => "color: red")
671
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
672
+ "<option value=\"\">No Zone</option>\n" +
673
+ "<option value=\"A\">A</option>\n" +
674
+ "<option value=\"B\">B</option>\n" +
675
+ "<option value=\"C\">C</option>\n" +
676
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
677
+ "<option value=\"E\">E</option>" +
678
+ "</select>",
679
+ html
680
+ assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
681
+ { :include_blank => 'No Zone' }, :style => "color: red")
682
+ end
589
683
 
590
- def test_time_zone_select_with_blank_and_style
591
- @firm = Firm.new("D")
592
- html = time_zone_select("firm", "time_zone", nil,
593
- { :include_blank => true }, "style" => "color: red")
594
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
595
- "<option value=\"\"></option>\n" +
596
- "<option value=\"A\">A</option>\n" +
597
- "<option value=\"B\">B</option>\n" +
598
- "<option value=\"C\">C</option>\n" +
599
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
600
- "<option value=\"E\">E</option>" +
601
- "</select>",
602
- html
603
- assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
604
- { :include_blank => true }, :style => "color: red")
605
- end
684
+ def test_time_zone_select_with_priority_zones
685
+ @firm = Firm.new("D")
686
+ zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ]
687
+ html = time_zone_select("firm", "time_zone", zones )
688
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
689
+ "<option value=\"A\">A</option>\n" +
690
+ "<option value=\"D\" selected=\"selected\">D</option>" +
691
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
692
+ "<option value=\"B\">B</option>\n" +
693
+ "<option value=\"C\">C</option>\n" +
694
+ "<option value=\"E\">E</option>" +
695
+ "</select>",
696
+ html
697
+ end
606
698
 
607
- def test_time_zone_select_with_blank_as_string_and_style
608
- @firm = Firm.new("D")
609
- html = time_zone_select("firm", "time_zone", nil,
610
- { :include_blank => 'No Zone' }, "style" => "color: red")
611
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
612
- "<option value=\"\">No Zone</option>\n" +
613
- "<option value=\"A\">A</option>\n" +
614
- "<option value=\"B\">B</option>\n" +
615
- "<option value=\"C\">C</option>\n" +
616
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
617
- "<option value=\"E\">E</option>" +
618
- "</select>",
619
- html
620
- assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
621
- { :include_blank => 'No Zone' }, :style => "color: red")
622
- end
699
+ def test_time_zone_select_with_priority_zones_as_regexp
700
+ @firm = Firm.new("D")
701
+ @fake_timezones.each_with_index do |tz, i|
702
+ tz.stubs(:=~).returns(i.zero? || i == 3)
703
+ end
704
+
705
+ html = time_zone_select("firm", "time_zone", /A|D/)
706
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
707
+ "<option value=\"A\">A</option>\n" +
708
+ "<option value=\"D\" selected=\"selected\">D</option>" +
709
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
710
+ "<option value=\"B\">B</option>\n" +
711
+ "<option value=\"C\">C</option>\n" +
712
+ "<option value=\"E\">E</option>" +
713
+ "</select>",
714
+ html
715
+ end
623
716
 
624
- def test_time_zone_select_with_priority_zones
625
- @firm = Firm.new("D")
626
- zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ]
627
- html = time_zone_select("firm", "time_zone", zones )
717
+ def test_time_zone_select_with_default_time_zone_and_nil_value
718
+ @firm = Firm.new()
719
+ @firm.time_zone = nil
720
+ html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
628
721
  assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
629
722
  "<option value=\"A\">A</option>\n" +
630
- "<option value=\"D\" selected=\"selected\">D</option>" +
631
- "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
632
- "<option value=\"B\">B</option>\n" +
723
+ "<option value=\"B\" selected=\"selected\">B</option>\n" +
633
724
  "<option value=\"C\">C</option>\n" +
725
+ "<option value=\"D\">D</option>\n" +
634
726
  "<option value=\"E\">E</option>" +
635
727
  "</select>",
636
728
  html
637
- end
638
-
639
- def test_time_zone_select_with_priority_zones_as_regexp
640
- @firm = Firm.new("D")
641
- @fake_timezones.each_with_index do |tz, i|
642
- tz.stubs(:=~).returns(i.zero? || i == 3)
643
- end
729
+ end
644
730
 
645
- html = time_zone_select("firm", "time_zone", /A|D/)
731
+ def test_time_zone_select_with_default_time_zone_and_value
732
+ @firm = Firm.new('D')
733
+ html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
646
734
  assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
647
735
  "<option value=\"A\">A</option>\n" +
648
- "<option value=\"D\" selected=\"selected\">D</option>" +
649
- "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
650
736
  "<option value=\"B\">B</option>\n" +
651
737
  "<option value=\"C\">C</option>\n" +
738
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
652
739
  "<option value=\"E\">E</option>" +
653
740
  "</select>",
654
741
  html
655
- end
742
+ end
656
743
 
657
- def test_time_zone_select_with_default_time_zone_and_nil_value
658
- @firm = Firm.new()
659
- @firm.time_zone = nil
660
- html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
661
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
662
- "<option value=\"A\">A</option>\n" +
663
- "<option value=\"B\" selected=\"selected\">B</option>\n" +
664
- "<option value=\"C\">C</option>\n" +
665
- "<option value=\"D\">D</option>\n" +
666
- "<option value=\"E\">E</option>" +
667
- "</select>",
668
- html
669
- end
744
+ private
670
745
 
671
- def test_time_zone_select_with_default_time_zone_and_value
672
- @firm = Firm.new('D')
673
- html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
674
- assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
675
- "<option value=\"A\">A</option>\n" +
676
- "<option value=\"B\">B</option>\n" +
677
- "<option value=\"C\">C</option>\n" +
678
- "<option value=\"D\" selected=\"selected\">D</option>\n" +
679
- "<option value=\"E\">E</option>" +
680
- "</select>",
681
- html
746
+ def dummy_posts
747
+ [ Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
748
+ Post.new("Babe went home", "Babe", "To a little house", "shh!"),
749
+ Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ]
682
750
  end
683
-
684
- end
685
- end
751
+ end