aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/form_options_helper_test.rb
diff options
context:
space:
mode:
authorpleax <aka.pleax@gmail.com>2010-05-15 13:53:59 +0400
committerJosé Valim <jose.valim@gmail.com>2010-05-16 14:33:04 +0200
commit2dc1402417242784a738321e7edd521f8ec7ac83 (patch)
treea154a6b4e5f4a4588cb237b0d9664efe8342d146 /actionpack/test/template/form_options_helper_test.rb
parentfc2480a277fd4753aebf68dcf8787d24e00bd057 (diff)
downloadrails-2dc1402417242784a738321e7edd521f8ec7ac83.tar.gz
rails-2dc1402417242784a738321e7edd521f8ec7ac83.tar.bz2
rails-2dc1402417242784a738321e7edd521f8ec7ac83.zip
added support for html attributes in options_for_select [#2165]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/test/template/form_options_helper_test.rb')
-rw-r--r--actionpack/test/template/form_options_helper_test.rb56
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 98503c32fd..19b73aa810 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -767,6 +767,62 @@ class FormOptionsHelperTest < ActionView::TestCase
html
end
+ def test_options_for_select_with_element_attributes
+ assert_dom_equal(
+ "<option value=\"&lt;Denmark&gt;\" class=\"bold\">&lt;Denmark&gt;</option>\n<option value=\"USA\" onclick=\"alert('Hello World');\">USA</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Germany\">Germany</option>",
+ options_for_select([ [ "<Denmark>", { :class => 'bold' } ], [ "USA", { :onclick => "alert('Hello World');" } ], [ "Sweden" ], "Germany" ])
+ )
+ end
+
+ def test_options_for_select_with_element_attributes_and_selection
+ assert_dom_equal(
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\" class=\"bold\" selected=\"selected\">USA</option>\n<option value=\"Sweden\">Sweden</option>",
+ options_for_select([ "<Denmark>", [ "USA", { :class => 'bold' } ], "Sweden" ], "USA")
+ )
+ end
+
+ def test_options_for_select_with_element_attributes_and_selection_array
+ assert_dom_equal(
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\" class=\"bold\" selected=\"selected\">USA</option>\n<option value=\"Sweden\" selected=\"selected\">Sweden</option>",
+ options_for_select([ "<Denmark>", [ "USA", { :class => 'bold' } ], "Sweden" ], [ "USA", "Sweden" ])
+ )
+ end
+
+ def test_option_html_attributes_from_without_hash
+ assert_dom_equal(
+ "",
+ option_html_attributes([ 'foo', 'bar' ])
+ )
+ end
+
+ def test_option_html_attributes_with_single_element_hash
+ assert_dom_equal(
+ " class=\"fancy\"",
+ option_html_attributes([ 'foo', 'bar', { :class => 'fancy' } ])
+ )
+ end
+
+ def test_option_html_attributes_with_multiple_element_hash
+ assert_dom_equal(
+ " class=\"fancy\" onclick=\"alert('Hello World');\"",
+ option_html_attributes([ 'foo', 'bar', { :class => 'fancy', 'onclick' => "alert('Hello World');" } ])
+ )
+ end
+
+ def test_option_html_attributes_with_multiple_hashes
+ assert_dom_equal(
+ " class=\"fancy\" onclick=\"alert('Hello World');\"",
+ option_html_attributes([ 'foo', 'bar', { :class => 'fancy' }, { 'onclick' => "alert('Hello World');" } ])
+ )
+ end
+
+ def test_option_html_attributes_with_special_characters
+ assert_dom_equal(
+ " onclick=\"alert(&quot;&lt;code&gt;&quot;)\"",
+ option_html_attributes([ 'foo', 'bar', { :onclick => %(alert("<code>")) } ])
+ )
+ end
+
def test_grouped_collection_select
@continents = [
Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),