From db045dbbf60b53dbe013ef25554fd013baf88134 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 24 Nov 2004 01:04:44 +0000 Subject: Initial git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/template/form_options_helper_test.rb | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 actionpack/test/template/form_options_helper_test.rb (limited to 'actionpack/test/template/form_options_helper_test.rb') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb new file mode 100644 index 0000000000..fa0a37aa36 --- /dev/null +++ b/actionpack/test/template/form_options_helper_test.rb @@ -0,0 +1,165 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_options_helper' + +class FormOptionsHelperTest < Test::Unit::TestCase + include ActionView::Helpers::FormOptionsHelper + + old_verbose, $VERBOSE = $VERBOSE, nil + Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin) + Continent = Struct.new('Continent', :continent_name, :countries) + Country = Struct.new('Country', :country_id, :country_name) + $VERBOSE = old_verbose + + def test_collection_options + @posts = [ + Post.new(" went home", "", "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!") + ] + + assert_equal( + "\n\n", + options_from_collection_for_select(@posts, "author_name", "title") + ) + end + + + def test_collection_options_with_preselected_value + @posts = [ + Post.new(" went home", "", "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!") + ] + + assert_equal( + "\n\n", + options_from_collection_for_select(@posts, "author_name", "title", "Babe") + ) + end + + def test_collection_options_with_preselected_value_array + @posts = [ + Post.new(" went home", "", "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!") + ] + + assert_equal( + "\n\n", + options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ]) + ) + end + + def test_array_options_for_select + assert_equal( + "\n\n", + options_for_select([ "", "USA", "Sweden" ]) + ) + end + + def test_array_options_for_select_with_selection + assert_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], "") + ) + end + + def test_array_options_for_select_with_selection_array + assert_equal( + "\n\n", + options_for_select([ "Denmark", "", "Sweden" ], [ "", "Sweden" ]) + ) + end + + def test_hash_options_for_select + assert_equal( + "\n", + options_for_select({ "$" => "Dollar", "" => "" }) + ) + end + + def test_hash_options_for_select_with_selection + assert_equal( + "\n", + options_for_select({ "$" => "Dollar", "" => "" }, "Dollar") + ) + end + + def test_hash_options_for_select_with_selection + assert_equal( + "\n", + options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]) + ) + end + + def test_html_option_groups_from_collection + @continents = [ + Continent.new("", [Country.new("", ""), Country.new("so", "Somalia")] ), + Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] ) + ] + + assert_equal( + "\n\n", + option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk") + ) + end + + def test_select + @post = Post.new + @post.category = "" + assert_equal( + "", + select("post", "category", %w( abe hest)) + ) + end + + def test_select_with_blank + @post = Post.new + @post.category = "" + assert_equal( + "", + select("post", "category", %w( abe hest), :include_blank => true) + ) + end + + def test_collection_select + @posts = [ + Post.new(" went home", "", "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_equal( + "", + collection_select("post", "author_name", @posts, "author_name", "author_name") + ) + end + + def test_collection_select_with_blank_and_style + @posts = [ + Post.new(" went home", "", "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_equal( + "", + collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") + ) + end + + def test_country_select + @post = Post.new + @post.origin = "Denmark" + assert_equal( + "", + country_select("post", "origin") + ) + end +end -- cgit v1.2.3