From 72608521871f73d6b07afa5f6f36e0dedcf1d079 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 4 Jan 2009 14:54:35 +0000 Subject: Fix date_select within fields_for with an index [#1666 state:resolved] [Josh, Frederick Cheung] Signed-off-by: Frederick Cheung --- actionpack/test/template/date_helper_test.rb | 95 +++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 15 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 6ec01b7a8f..92cdce2e45 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1228,6 +1228,38 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal(expected, output_buffer) end + def test_date_select_within_fields_for_with_index + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + id = 27 + + fields_for :post, @post, :index => id do |f| + concat f.date_select(:written_on) + end + + expected = "\n" + expected << "\n" + expected << "\n" + + assert_dom_equal(expected, output_buffer) + end + + def test_date_select_within_fields_for_with_blank_index + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + id = nil + + fields_for :post, @post, :index => id do |f| + concat f.date_select(:written_on) + end + + expected = "\n" + expected << "\n" + expected << "\n" + + assert_dom_equal(expected, output_buffer) + end + def test_date_select_with_index @post = Post.new @post.written_on = Date.new(2004, 6, 15) @@ -1243,7 +1275,6 @@ class DateHelperTest < ActionView::TestCase expected << %{\n" assert_dom_equal expected, date_select("post", "written_on", :index => id) @@ -1330,13 +1361,13 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :include_blank => true) end - + def test_date_select_with_nil_and_blank_and_order @post = Post.new start_year = Time.now.year-5 end_year = Time.now.year+5 - + expected = '' + "\n" expected << %{\n} + expected << %{\n\n\n\n\n\n\n\n\n\n\n} + expected << "\n" + + expected << %{\n" + + expected << %{\n" + + expected << " — " + + expected << %{\n" + expected << " : " + expected << %{\n" + + assert_dom_equal expected, output_buffer + end + def test_datetime_select_with_auto_index @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) @@ -2253,7 +2318,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2008, 7, 16, 23, 30) - options = { + options = { :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2265,7 +2330,7 @@ class DateHelperTest < ActionView::TestCase # note: the literal hash is intentional to show that the actual options hash isn't modified # don't change this! - assert_equal({ + assert_equal({ :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2279,7 +2344,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2008, 7, 16, 23, 30) - options = { + options = { :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2291,7 +2356,7 @@ class DateHelperTest < ActionView::TestCase # note: the literal hash is intentional to show that the actual options hash isn't modified # don't change this! - assert_equal({ + assert_equal({ :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2305,7 +2370,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2008, 7, 16, 23, 30) - options = { + options = { :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2317,7 +2382,7 @@ class DateHelperTest < ActionView::TestCase # note: the literal hash is intentional to show that the actual options hash isn't modified # don't change this! - assert_equal({ + assert_equal({ :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2328,7 +2393,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_should_not_change_passed_options_hash - options = { + options = { :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2340,7 +2405,7 @@ class DateHelperTest < ActionView::TestCase # note: the literal hash is intentional to show that the actual options hash isn't modified # don't change this! - assert_equal({ + assert_equal({ :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2351,7 +2416,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_should_not_change_passed_options_hash - options = { + options = { :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2363,7 +2428,7 @@ class DateHelperTest < ActionView::TestCase # note: the literal hash is intentional to show that the actual options hash isn't modified # don't change this! - assert_equal({ + assert_equal({ :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2374,7 +2439,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_should_not_change_passed_options_hash - options = { + options = { :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, @@ -2386,7 +2451,7 @@ class DateHelperTest < ActionView::TestCase # note: the literal hash is intentional to show that the actual options hash isn't modified # don't change this! - assert_equal({ + assert_equal({ :order => [ :year, :month, :day ], :default => { :year => 2008, :month => 7, :day => 16, :hour => 23, :minute => 30, :second => 1 }, :discard_type => false, -- cgit v1.2.3