From 6608a3ef37a8f998958b867a1be186d33edbc151 Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Sun, 10 Feb 2008 22:26:16 +0000 Subject: Adding TimeWithZone #to_yaml, #to_datetime, #eql? and method aliases for duck-typing compatibility with Time git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8854 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/time_with_zone_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activesupport/test/core_ext') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index a286fda4e2..38646caa79 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -86,6 +86,10 @@ uses_tzinfo 'TimeWithZoneTest' do assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema end + def test_to_yaml + assert_equal "--- 1999-12-31 19:00:00 -05:00\n", @twz.to_yaml + end + def test_httpdate assert_equal 'Sat, 01 Jan 2000 00:00:00 GMT', @twz.httpdate end @@ -111,6 +115,11 @@ uses_tzinfo 'TimeWithZoneTest' do assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) end + + def test_eql? + assert @twz.eql?(Time.utc(2000)) + assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone["Hawaii"]) ) + end def test_plus assert_equal Time.utc(1999, 12, 31, 19, 0 ,5), (@twz + 5).time @@ -158,6 +167,10 @@ uses_tzinfo 'TimeWithZoneTest' do def test_to_time assert_equal @twz, @twz.to_time end + + def test_to_datetime + assert_equal DateTime.civil(1999, 12, 31, 19, 0, 0, Rational(-18_000, 86_400)), @twz.to_datetime + end def test_acts_like_time assert @twz.acts_like?(:time) -- cgit v1.2.3