From aea3820261c5bba9afcc775bf78d997e43db42f0 Mon Sep 17 00:00:00 2001 From: Colin Burn-Murdoch Date: Sun, 13 Jan 2013 20:35:15 +0000 Subject: [PATCH] Allow value to be set on date_select --- actionpack/CHANGELOG.md | 4 ++++ .../action_view/helpers/tags/date_select.rb | 2 +- actionpack/test/template/date_helper_test.rb | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 2cb7af05e5214..a8325b86fc06c 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* Allow value to be set on date_select tag helper. + + *Colin Burn-Murdoch* + * Fixed json params parsing regression for non-object JSON content. *Dylan Smith* diff --git a/actionpack/lib/action_view/helpers/tags/date_select.rb b/actionpack/lib/action_view/helpers/tags/date_select.rb index 6c400f85cbf9c..f073c63f73ad1 100644 --- a/actionpack/lib/action_view/helpers/tags/date_select.rb +++ b/actionpack/lib/action_view/helpers/tags/date_select.rb @@ -27,7 +27,7 @@ def select_type end def datetime_selector(options, html_options) - datetime = value(object) || default_datetime(options) + datetime = options[:value] || value(object) || default_datetime(options) @auto_index ||= nil options = options.dup diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index f9ce63fcb0a18..0ab5c15131f7c 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1510,6 +1510,27 @@ def test_date_select assert_dom_equal expected, date_select("post", "written_on") end + + def test_date_select_with_value + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + + expected = %{\n" + + expected << %{\n" + + expected << %{\n" + + assert_dom_equal expected, date_select("post", "written_on", :value => '2004-07-10'.to_date) + + end def test_date_select_without_day @post = Post.new