Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better tests for Time#to_time, Date#to_date and DateTime#to_datetime

These should all return self, except for Time#to_time on Ruby 1.9, which
returns utc as the native method which is not overridden by AS but
perhaps should be.
  • Loading branch information...
commit 222228ec15347dcd25993712b0a70504435a11f4 1 parent 0784a7c
@adzap authored
View
4 activesupport/test/core_ext/date_ext_test.rb
@@ -36,7 +36,9 @@ def test_to_datetime
end
def test_to_date
- assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date
+ date = Date.new(2005, 2, 21)
+
+ assert date.equal?(date)
end
def test_change
View
4 activesupport/test/core_ext/date_time_ext_test.rb
@@ -30,7 +30,9 @@ def test_to_date
end
def test_to_datetime
- assert_equal DateTime.new(2005, 2, 21, 14, 30, 0), DateTime.new(2005, 2, 21, 14, 30, 0).to_datetime
+ datetime = DateTime.new(2005, 2, 21, 14, 30, 0)
+
+ assert datetime.equal?(datetime.to_datetime)
end
def test_to_time
View
11 activesupport/test/core_ext/time_ext_test.rb
@@ -587,8 +587,15 @@ def test_to_datetime
assert_equal ::Date::ITALY, Time.utc(2005, 2, 21, 17, 44, 30).to_datetime.start # use Ruby's default start value
end
- def test_to_time
- assert_equal Time.local(2005, 2, 21, 17, 44, 30), Time.local(2005, 2, 21, 17, 44, 30).to_time
+ if RUBY_VERSION < '1.9'
+ def test_to_time
+ time = Time.local(2005, 2, 21, 17, 44, 30)
+ assert time.equal?(time.to_time)
+ end
+ else
+ def test_to_time
+ assert_equal Time.local(2005, 2, 21, 17, 44, 30), Time.local(2005, 2, 21, 17, 44, 30).to_time
+ end
end
# NOTE: this test seems to fail (changeset 1958) only on certain platforms,
Please sign in to comment.
Something went wrong with that request. Please try again.