Permalink
Browse files

fix conditions when DateTime#to_date and DateTime#xmlschema methods a…

…re defined
  • Loading branch information...
1 parent a82e067 commit 5fcaf917612c61174f55bbd2301131ccdbec51fb @rsim rsim committed Feb 16, 2010
View
6 activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -60,7 +60,7 @@ def readable_inspect
# 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
@@ -71,7 +71,7 @@ def to_time
# 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)
def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0)
offset = utc_or_local.to_sym == :local ? local_offset : 0
@@ -81,7 +81,7 @@ def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, se
# 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
View
2 activesupport/test/abstract_unit.rb
@@ -18,7 +18,7 @@
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'
View
4 activesupport/test/core_ext/date_time_ext_test.rb
@@ -26,11 +26,11 @@ def test_custom_date_format
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

0 comments on commit 5fcaf91

Please sign in to comment.