From 726b5d79845c0ef50db64e2991bfec4e108faf4d Mon Sep 17 00:00:00 2001 From: Daniel Neighman Date: Thu, 22 Apr 2010 09:43:33 +1000 Subject: updates String#to_(date|date_time|time) to return nil for blank strings --- activesupport/test/core_ext/string_ext_test.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activesupport/test/core_ext') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 58ca215970..97b08da0e4 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -117,17 +117,20 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal Time.local(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time(:local) assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time assert_equal Time.local_time(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:local) + assert_equal nil, "".to_time end - + def test_string_to_datetime assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime assert_equal 0, "2039-02-27 23:50".to_datetime.offset # use UTC offset assert_equal ::Date::ITALY, "2039-02-27 23:50".to_datetime.start # use Ruby's default start value assert_equal DateTime.civil(2039, 2, 27, 23, 50, 19 + Rational(275038, 1000000), "-04:00"), "2039-02-27T23:50:19.275038-04:00".to_datetime + assert_equal nil, "".to_datetime end - + def test_string_to_date assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date + assert_equal nil, "".to_date end def test_access @@ -255,7 +258,7 @@ end string.rb - Interpolation for String. Copyright (C) 2005-2009 Masao Mutoh - + You may redistribute it and/or modify it under the same license terms as Ruby. =end -- cgit v1.2.3