commit d0ad5413172103161c71b04168bd446a3f48d5ae Author: Nolan Eakins Date: Wed Apr 8 13:52:51 2009 -0400 Fixes #2457 by making the hidden date fields include today's date. diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index c74909a..8d49595 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -678,7 +678,9 @@ module ActionView def select_day if @options[:use_hidden] || @options[:discard_day] - build_hidden(:day, day) + val = day + val ||= Date.today.day if @options[:include_blank] + build_hidden(:day, val) else build_options_and_select(:day, day, :start => 1, :end => 31, :leading_zeros => false) end @@ -686,7 +688,9 @@ module ActionView def select_month if @options[:use_hidden] || @options[:discard_month] - build_hidden(:month, month) + val = month + val ||= Date.today.month if @options[:include_blank] + build_hidden(:month, val) else month_options = [] 1.upto(12) do |month_number| @@ -707,6 +711,7 @@ module ActionView end if @options[:use_hidden] || @options[:discard_year] + val = middle_year if @options[:include_blank] && (!@date_time || @datetime == 0) build_hidden(:year, val) else options = {} diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 2e4763f..468a601 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1388,7 +1388,7 @@ class DateHelperTest < ActionView::TestCase start_year = Time.now.year-5 end_year = Time.now.year+5 - expected = '' + "\n" + expected = %{\n} expected << %{\n} + expected << %{\n} + expected << %{\n} + + expected << %(\n" + expected << " : " + expected << %(\n" + + assert_dom_equal expected, time_select("post", "written_on", :include_blank => true) + end + + def test_time_select_with_include_blank_and_nil_time + @post = Post.new + + expected = %{\n} + expected << %{\n} + expected << %{\n} + + expected << %(\n" + expected << " : " + expected << %(\n" + + assert_dom_equal expected, time_select("post", "written_on", :include_blank => true) + end + def test_time_select_without_date_hidden_fields @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35)