From 56800ccc9d65784bb9c808e4962e673652330d4d Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Tue, 16 Feb 2010 21:43:13 +0200 Subject: [PATCH] fix conditions when DateTime#to_date and DateTime#xmlschema methods are defined --- .../core_ext/date_time/conversions.rb | 6 +++--- activesupport/test/abstract_unit.rb | 2 +- activesupport/test/core_ext/date_time_ext_test.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index 47a3183..44d86f2 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -58,7 +58,7 @@ class DateTime # Converts self to a Ruby Date object; time portion is discarded def to_date ::Date.new(year, month, day) - end unless method_defined?(:to_date) + end unless instance_methods(false).include?(:to_date) # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time @@ -69,12 +69,12 @@ class DateTime # To be able to keep Times, Dates and DateTimes interchangeable on conversions def to_datetime self - end unless method_defined?(:to_datetime) + end unless instance_methods(false).include?(:to_datetime) # Converts datetime to an appropriate format for use in XML def xmlschema strftime("%Y-%m-%dT%H:%M:%S%Z") - end unless method_defined?(:xmlschema) + end unless instance_methods(false).include?(:xmlschema) # Converts self to a floating-point number of seconds since the Unix epoch def to_f diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index c4ef102..ec10167 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -10,7 +10,7 @@ ENV['NO_RELOAD'] = '1' require 'active_support' # Include shims until we get off 1.8.6 -require 'active_support/ruby/shim' +require 'active_support/ruby/shim' if RUBY_VERSION < '1.8.7' def uses_memcached(test_name) require 'memcache' diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 278c057..6c82047 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -26,11 +26,11 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase end def test_to_date - assert_equal Date.new(2005, 2, 21), DateTime.new(2005, 2, 21).to_date + assert_equal Date.new(2005, 2, 21), DateTime.new(2005, 2, 21, 14, 30, 0).to_date end def test_to_datetime - assert_equal DateTime.new(2005, 2, 21), DateTime.new(2005, 2, 21).to_datetime + assert_equal DateTime.new(2005, 2, 21, 14, 30, 0), DateTime.new(2005, 2, 21, 14, 30, 0).to_datetime end def test_to_time -- 1.6.4.4