From 947cec29d5f074682052e8412904cc88a914fdbc Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 13 Nov 2005 11:13:11 +0000 Subject: Added FormHelper#form_for and FormHelper#fields_for that makes it easier to work with forms for single objects also if they don't reside in instance variables [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3003 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/template/form_options_helper_test.rb | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (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 index 36d68492ec..4d22f0cfef 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -23,6 +23,7 @@ end ActionView::Helpers::FormOptionsHelper::TimeZone = MockTimeZone class FormOptionsHelperTest < Test::Unit::TestCase + include ActionView::Helpers::FormHelper include ActionView::Helpers::FormOptionsHelper silence_warnings do @@ -222,6 +223,22 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_select_under_fields_for + @post = Post.new + @post.category = "" + + _erbout = '' + + fields_for :post => @post do |f| + _erbout.concat f.select(:category, %w( abe hest)) + end + + assert_dom_equal( + "", + _erbout + ) + end + def test_select_with_blank @post = Post.new @post.category = "" @@ -283,6 +300,28 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_collection_select_under_fields_for + @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" + + _erbout = '' + + fields_for :post => @post do |f| + _erbout.concat f.collection_select(:author_name, @posts, :author_name, :author_name) + end + + assert_dom_equal( + "", + _erbout + ) + end + def test_collection_select_with_blank_and_style @posts = [ Post.new(" went home", "", "To a little house", "shh!"), @@ -324,6 +363,27 @@ class FormOptionsHelperTest < Test::Unit::TestCase html end + def test_time_zone_select_under_fields_for + @firm = Firm.new("D") + + _erbout = '' + + fields_for :firm => @firm do |f| + _erbout.concat f.time_zone_select(:time_zone) + end + + assert_dom_equal( + "", + _erbout + ) + end + def test_time_zone_select_with_blank @firm = Firm.new("D") html = time_zone_select("firm", "time_zone", nil, :include_blank => true) -- cgit v1.2.3