diff options
author | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-03 23:43:53 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-03 23:47:46 +0100 |
commit | 08073125a5bd4cae0f2e02723e7743a389d496cd (patch) | |
tree | e290932b105597ea893565b1f62420cf6b0c4dd8 /activesupport/test/core_ext | |
parent | ae2f193c0379453f73ae08a3df541d2cb0ae00e2 (diff) | |
download | rails-08073125a5bd4cae0f2e02723e7743a389d496cd.tar.gz rails-08073125a5bd4cae0f2e02723e7743a389d496cd.tar.bz2 rails-08073125a5bd4cae0f2e02723e7743a389d496cd.zip |
Call super instead of returning nil for DateTime#<=>
The native DateTime#<=> implementation can be used to compare instances
with numeric values being considered as astronomical julian day numbers
so we should call that instead of returning nil.
Fixes #24228.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index b183a20e0d..16efeeadd5 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -354,6 +354,24 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase assert_equal nil, DateTime.civil(2000) <=> "Invalid as Time" end + def test_compare_with_integer + assert_equal 1, DateTime.civil(1970, 1, 1, 12, 0, 0) <=> 2440587 + assert_equal 0, DateTime.civil(1970, 1, 1, 12, 0, 0) <=> 2440588 + assert_equal(-1, DateTime.civil(1970, 1, 1, 12, 0, 0) <=> 2440589) + end + + def test_compare_with_float + assert_equal 1, DateTime.civil(1970) <=> 2440586.5 + assert_equal 0, DateTime.civil(1970) <=> 2440587.5 + assert_equal(-1, DateTime.civil(1970) <=> 2440588.5) + end + + def test_compare_with_rational + assert_equal 1, DateTime.civil(1970) <=> Rational(4881173, 2) + assert_equal 0, DateTime.civil(1970) <=> Rational(4881175, 2) + assert_equal(-1, DateTime.civil(1970) <=> Rational(4881177, 2)) + end + def test_to_f assert_equal 946684800.0, DateTime.civil(2000).to_f assert_equal 946684800.0, DateTime.civil(1999,12,31,19,0,0,Rational(-5,24)).to_f |