From b81c46e6bd6997bf6637b5086bbb9cbb32664974 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 10 Nov 2005 22:08:20 +0000 Subject: options_for_select allows any objects which respond_to? :first and :last rather than restricting to Array and Range. Closes #2824. References [2126]. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2977 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/template/form_options_helper_test.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (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 cc68312fb8..36d68492ec 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -103,25 +103,35 @@ class FormOptionsHelperTest < Test::Unit::TestCase options_for_select([ "ruby", "rubyonrails" ], "ruby") ) end - + def test_hash_options_for_select assert_dom_equal( "\n", options_for_select({ "$" => "Dollar", "" => "" }) ) - end - - def test_hash_options_for_select_with_selection assert_dom_equal( "\n", options_for_select({ "$" => "Dollar", "" => "" }, "Dollar") ) + assert_dom_equal( + "\n", + options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]) + ) end - def test_hash_options_for_select_with_selection + def test_ducktyped_options_for_select + quack = Struct.new(:first, :last) + assert_dom_equal( + "\n", + options_for_select([quack.new("", ""), quack.new("$", "Dollar")]) + ) + assert_dom_equal( + "\n", + options_for_select([quack.new("", ""), quack.new("$", "Dollar")], "Dollar") + ) assert_dom_equal( "\n", - options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]) + options_for_select([quack.new("", ""), quack.new("$", "Dollar")], ["Dollar", ""]) ) end -- cgit v1.2.3