From 1525f3816e9b51d93d2e1356d1b90ba49213d325 Mon Sep 17 00:00:00 2001 From: Tekin Suleyman Date: Sat, 14 Feb 2009 00:37:24 +0000 Subject: Enhanced form option helpers to add support for disabled option tags and use of anonymous functions for specifying selected and disabled values from collections. Signed-off-by: Michael Koziarski --- .../test/template/form_options_helper_test.rb | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 2dbd2ecdd4..78db87971b 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -45,6 +45,41 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_collection_options_with_proc_for_selected + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", lambda{|p| p.author_name == 'Babe' }) + ) + end + + def test_collection_options_with_disabled_value + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => "Babe") + ) + end + + def test_collection_options_with_disabled_array + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => [ "Babe", "Cabe" ]) + ) + end + + def test_collection_options_with_preselected_and_disabled_value + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :selected => "Cabe", :disabled => "Babe") + ) + end + + def test_collection_options_with_proc_for_disabled + assert_dom_equal( + "\n\n", + options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| %w(Babe Cabe).include? p.author_name }) + ) + end + def test_array_options_for_select assert_dom_equal( "\n\n", @@ -66,6 +101,27 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_array_options_for_select_with_disabled_value + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], :disabled => "") + ) + end + + def test_array_options_for_select_with_disabled_array + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], :disabled => ["", "Sweden"]) + ) + end + + def test_array_options_for_select_with_selection_and_disabled_value + assert_dom_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], :selected => "Denmark", :disabled => "") + ) + end + def test_array_options_for_string_include_in_other_string_bug_fix assert_dom_equal( "\n", @@ -352,6 +408,24 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_disabled_value + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest ), :disabled => 'hest') + ) + end + + def test_select_with_disabled_array + @post = Post.new + @post.category = "" + assert_dom_equal( + "", + select("post", "category", %w( abe hest ), :disabled => ['hest', 'abe']) + ) + end + def test_collection_select @post = Post.new @post.author_name = "Babe" @@ -448,6 +522,16 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_collection_select_with_disabled + @post = Post.new + @post.author_name = "Babe" + + assert_dom_equal( + "", + collection_select("post", "author_name", dummy_posts, "author_name", "author_name", :disabled => 'Cabe') + ) + end + def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) -- cgit v1.2.3