From 3daff0508bd93cfcbe8917e745a28f5a738fcdaa Mon Sep 17 00:00:00 2001 From: Colin Burn-Murdoch Date: Wed, 16 Jan 2013 18:51:34 +0000 Subject: Fix date_select :selected option so you can pass it nil --- actionpack/test/template/date_helper_test.rb | 65 +++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template/date_helper_test.rb') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index d622392caf..f11adefad8 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1529,7 +1529,24 @@ class DateHelperTest < ActionView::TestCase expected << "\n" assert_dom_equal expected, date_select("post", "written_on", :selected => Date.new(2004, 07, 10)) + end + + def test_date_select_with_selected_nil + @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", include_blank: true, discard_year: true, selected: nil) end def test_date_select_without_day @@ -2005,7 +2022,26 @@ class DateHelperTest < ActionView::TestCase 0.upto(59) { |i| expected << %(\n) } expected << "\n" - assert_dom_equal expected, time_select("post", "written_on", :selected => Time.local(2004, 6, 15, 12, 20, 30)) + assert_dom_equal expected, time_select("post", "written_on", selected: Time.local(2004, 6, 15, 12, 20, 30)) + end + + def test_time_select_with_selected_nil + @post = Post.new + @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) + + expected = %{\n} + expected << %{\n} + expected << %{\n} + + expected << %(\n" + expected << " : " + expected << %(\n" + + assert_dom_equal expected, time_select("post", "written_on", discard_year: true, discard_month: true, discard_day: true, selected: nil) end def test_time_select_without_date_hidden_fields @@ -2234,6 +2270,33 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, datetime_select("post", "updated_at", :selected => Time.local(2004, 3, 10, 12, 30)) end + def test_datetime_select_with_selected_nil + @post = Post.new + @post.updated_at = Time.local(2004, 6, 15, 16, 35) + + expected = '' + "\n" + + expected << %{\n" + + expected << %{\n" + + expected << " — " + + expected << %{\n" + expected << " : " + expected << %{\n" + + assert_dom_equal expected, datetime_select("post", "updated_at", discard_year: true, selected: nil) + end + def test_datetime_select_defaults_to_time_zone_now_when_config_time_zone_is_set # The love zone is UTC+0 mytz = Class.new(ActiveSupport::TimeZone) { -- cgit v1.2.3