diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-18 05:29:22 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-18 05:29:22 +0000 |
commit | b6541b8dcc6df9c92d946e1f76ec03f448d7fba4 (patch) | |
tree | 6e8ac4ffe796d9a552260fe2da24b5f9d266bb7e /actionpack/test | |
parent | f7bb3ddce85dcafe8ae2c52f7b7fbd53b0859732 (diff) | |
download | rails-b6541b8dcc6df9c92d946e1f76ec03f448d7fba4.tar.gz rails-b6541b8dcc6df9c92d946e1f76ec03f448d7fba4.tar.bz2 rails-b6541b8dcc6df9c92d946e1f76ec03f448d7fba4.zip |
select :include_blank option can be set to a string instead of true, which just uses an empty string. Closes #7664.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6763 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 5ca1d037df..3c0a96b0de 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -252,6 +252,15 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_select_with_blank_as_string + @post = Post.new + @post.category = "<mus>" + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">None</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>", + select("post", "category", %w( abe <mus> hest), :include_blank => 'None') + ) + end + def test_select_with_default_prompt @post = Post.new @post.category = "" @@ -360,6 +369,22 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_collection_select_with_blank_as_string_and_style + @posts = [ + Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"), + Post.new("Babe went home", "Babe", "To a little house", "shh!"), + Post.new("Cabe went home", "Cabe", "To a little house", "shh!") + ] + + @post = Post.new + @post.author_name = "Babe" + + assert_dom_equal( + "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\">No Selection</option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>", + collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px") + ) + end + def test_collection_select_with_multiple_option_appends_array_brackets @posts = [ Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"), @@ -439,6 +464,20 @@ class FormOptionsHelperTest < Test::Unit::TestCase html end + def test_time_zone_select_with_blank_as_string + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, :include_blank => 'No Zone') + assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" + + "<option value=\"\">No Zone</option>\n" + + "<option value=\"A\">A</option>\n" + + "<option value=\"B\">B</option>\n" + + "<option value=\"C\">C</option>\n" + + "<option value=\"D\" selected=\"selected\">D</option>\n" + + "<option value=\"E\">E</option>" + + "</select>", + html + end + def test_time_zone_select_with_style @firm = Firm.new("D") html = time_zone_select("firm", "time_zone", nil, {}, @@ -472,6 +511,23 @@ class FormOptionsHelperTest < Test::Unit::TestCase { :include_blank => true }, :style => "color: red") end + def test_time_zone_select_with_blank_as_string_and_style + @firm = Firm.new("D") + html = time_zone_select("firm", "time_zone", nil, + { :include_blank => 'No Zone' }, "style" => "color: red") + assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" + + "<option value=\"\">No Zone</option>\n" + + "<option value=\"A\">A</option>\n" + + "<option value=\"B\">B</option>\n" + + "<option value=\"C\">C</option>\n" + + "<option value=\"D\" selected=\"selected\">D</option>\n" + + "<option value=\"E\">E</option>" + + "</select>", + html + assert_dom_equal html, time_zone_select("firm", "time_zone", nil, + { :include_blank => 'No Zone' }, :style => "color: red") + end + def test_time_zone_select_with_priority_zones @firm = Firm.new("D") zones = [ TimeZone.new("A"), TimeZone.new("D") ] |