From 2bf29b3485151f819318437561bea8abebe9427b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 23 Feb 2005 12:54:58 +0000 Subject: Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_zone_options_for_select to work with the new value object TimeZone in Active Record #688 [Jamis Buck] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@759 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/template/form_options_helper_test.rb | 158 +++++++++++++++++++++ 1 file changed, 158 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 8894e46865..606a5fe35b 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1,6 +1,26 @@ require 'test/unit' require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_options_helper' +class TimeZone + attr_reader :name + + def initialize( name ) + @name = name + end + + def self.all + [ "A", "B", "C", "D", "E" ].map { |s| new s } + end + + def ==( z ) + z && @name == z.name + end + + def to_s + @name + end +end + class FormOptionsHelperTest < Test::Unit::TestCase include ActionView::Helpers::FormOptionsHelper @@ -8,6 +28,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase 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) + Firm = Struct.new('Firm', :time_zone) $VERBOSE = old_verbose def test_collection_options @@ -104,6 +125,72 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_time_zone_options_no_parms + opts = time_zone_options_for_select + assert_equal "\n" + + "\n" + + "\n" + + "\n" + + "", + opts + end + + def test_time_zone_options_with_selected + opts = time_zone_options_for_select( TimeZone.new( "D" ) ) + assert_equal "\n" + + "\n" + + "\n" + + "\n" + + "", + opts + end + + def test_time_zone_options_with_unknown_selected + opts = time_zone_options_for_select( TimeZone.new( "K" ) ) + assert_equal "\n" + + "\n" + + "\n" + + "\n" + + "", + opts + end + + def test_time_zone_options_with_priority_zones + zones = [ TimeZone.new( "B" ), TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( nil, zones ) + assert_equal "\n" + + "" + + "\n" + + "\n" + + "\n" + + "", + opts + end + + def test_time_zone_options_with_selected_priority_zones + zones = [ TimeZone.new( "B" ), TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( TimeZone.new("E"), zones ) + assert_equal "\n" + + "" + + "\n" + + "\n" + + "\n" + + "", + opts + end + + def test_time_zone_options_with_unselected_priority_zones + zones = [ TimeZone.new( "B" ), TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( TimeZone.new("C"), zones ) + assert_equal "\n" + + "" + + "\n" + + "\n" + + "\n" + + "", + opts + end + def test_select @post = Post.new @post.category = "" @@ -162,4 +249,75 @@ class FormOptionsHelperTest < Test::Unit::TestCase country_select("post", "origin") ) end + + def test_time_zone_select + @firm = Firm.new( TimeZone.new( "D" ) ) + html = time_zone_select( "firm", "time_zone" ) + assert_equal "", + html + end + + def test_time_zone_select_with_blank + @firm = Firm.new(TimeZone.new("D")) + html = time_zone_select("firm", "time_zone", nil, :include_blank => true) + assert_equal "", + html + end + + def test_time_zone_select_with_style + @firm = Firm.new(TimeZone.new("D")) + html = time_zone_select("firm", "time_zone", nil, {}, + "style" => "color: red") + assert_equal "", + html + end + + def test_time_zone_select_with_blank_and_style + @firm = Firm.new(TimeZone.new("D")) + html = time_zone_select("firm", "time_zone", nil, + { :include_blank => true }, "style" => "color: red") + assert_equal "", + html + end + + def test_time_zone_select_with_priority_zones + @firm = Firm.new(TimeZone.new("D")) + zones = [ TimeZone.new("A"), TimeZone.new("D") ] + html = time_zone_select("firm", "time_zone", zones ) + assert_equal "", + html + end end -- cgit v1.2.3