diff options
author | José Valim <jose.valim@gmail.com> | 2011-07-11 10:25:04 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-07-11 10:25:04 -0700 |
commit | 1939fa3f169e4c44234aef0f336411fc01d0445f (patch) | |
tree | 498fe31d0d12fbdd04d3baeb057970c1674c9251 /actionpack/test/template/form_options_helper_test.rb | |
parent | 133a20354ef9872721e3b825daaf8eca686b4d37 (diff) | |
parent | 587dd7d56c1451c1d597535ede27c2163be72e0b (diff) | |
download | rails-1939fa3f169e4c44234aef0f336411fc01d0445f.tar.gz rails-1939fa3f169e4c44234aef0f336411fc01d0445f.tar.bz2 rails-1939fa3f169e4c44234aef0f336411fc01d0445f.zip |
Merge pull request #1722 from AndrewRadev/grouped-select
Make "select" helper handle nested collections
Diffstat (limited to 'actionpack/test/template/form_options_helper_test.rb')
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index a4599a3f00..6aea991f7c 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -385,6 +385,42 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_grouped_collection_as_nested_array + @post = Post.new + + countries_by_continent = [ + ["<Africa>", [["<South Africa>", "<sa>"], ["Somalia", "so"]]], + ["Europe", [["Denmark", "dk"], ["Ireland", "ie"]]], + ] + + assert_dom_equal( + [ + %Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>}, + %Q{<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>}, + %Q{<option value="ie">Ireland</option></optgroup></select>}, + ].join("\n"), + select("post", "origin", countries_by_continent) + ) + end + + def test_select_with_grouped_collection_as_hash + @post = Post.new + + countries_by_continent = { + "<Africa>" => [["<South Africa>", "<sa>"], ["Somalia", "so"]], + "Europe" => [["Denmark", "dk"], ["Ireland", "ie"]], + } + + assert_dom_equal( + [ + %Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>}, + %Q{<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>}, + %Q{<option value="ie">Ireland</option></optgroup></select>}, + ].join("\n"), + select("post", "origin", countries_by_continent) + ) + end + def test_select_with_boolean_method @post = Post.new @post.allow_comments = false |