diff options
author | Roque Pinel <repinel@gmail.com> | 2015-07-19 11:08:20 -0400 |
---|---|---|
committer | Roque Pinel <repinel@gmail.com> | 2015-07-19 11:17:51 -0400 |
commit | 46b5b8ef40d81d583978fc7f111f0cd4ead26dfc (patch) | |
tree | f36bd095390c8f0c03006900692644b5d30c296c /activesupport/test | |
parent | 3f1c5d39c01e13bcf9e34865f00ded56a3a321fc (diff) | |
download | rails-46b5b8ef40d81d583978fc7f111f0cd4ead26dfc.tar.gz rails-46b5b8ef40d81d583978fc7f111f0cd4ead26dfc.tar.bz2 rails-46b5b8ef40d81d583978fc7f111f0cd4ead26dfc.zip |
Fix `TimeWithZone#eql?` to handle `TimeWithZone` created from `DateTime`
Before:
```ruby
twz = DateTime.now.in_time_zone
twz.eql?(twz.dup) => false
```
Now:
```ruby
twz = DateTime.now.in_time_zone
twz.eql?(twz.dup) => true
```
Please notice that this fix the `TimeWithZone` comparison to itself,
not to `DateTime`. Based on #3725, `DateTime` should not be equal to
`TimeWithZone`.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 477a42114b..ccb7f02331 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -253,10 +253,14 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_eql? + assert_equal true, @twz.eql?(@twz.dup) assert_equal true, @twz.eql?(Time.utc(2000)) assert_equal true, @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) ) assert_equal false, @twz.eql?( Time.utc(2000, 1, 1, 0, 0, 1) ) assert_equal false, @twz.eql?( DateTime.civil(1999, 12, 31, 23, 59, 59) ) + + other_twz = ActiveSupport::TimeWithZone.new(DateTime.now.utc, @time_zone) + assert_equal true, other_twz.eql?(other_twz.dup) end def test_hash |