diff options
author | Jonas Nicklas <jonas.nicklas@gmail.com> | 2017-01-09 11:24:53 +0100 |
---|---|---|
committer | Jonas Nicklas <jonas.nicklas@gmail.com> | 2017-01-10 11:43:26 +0100 |
commit | 3d78949c7451858231cce883411a7ac2595f5780 (patch) | |
tree | 28a6ec957ccf2285acb49006a646fd4e1b808fe5 /activesupport/test | |
parent | 7f19f30819dd5a5a788ad9d8b12b5dda76559a12 (diff) | |
download | rails-3d78949c7451858231cce883411a7ac2595f5780.tar.gz rails-3d78949c7451858231cce883411a7ac2595f5780.tar.bz2 rails-3d78949c7451858231cce883411a7ac2595f5780.zip |
Make time travel work with subclasses of Time/Date/Datetime
Closes #27614
Previously when calling `now` on a subclass of e.g. `Time` it would return an instance of `Time` instead of returning an instance of the subclass. This way, we always return the correct class.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/time_travel_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb index c68be329bc..cfc6447360 100644 --- a/activesupport/test/time_travel_test.rb +++ b/activesupport/test/time_travel_test.rb @@ -3,6 +3,10 @@ require "active_support/core_ext/date_time" require "active_support/core_ext/numeric/time" class TimeTravelTest < ActiveSupport::TestCase + class TimeSubclass < ::Time; end + class DateSubclass < ::Date; end + class DateTimeSubclass < ::DateTime; end + def test_time_helper_travel Time.stub(:now, Time.now) do begin @@ -142,4 +146,19 @@ class TimeTravelTest < ActiveSupport::TestCase end end end + + def test_time_helper_travel_with_time_subclass + assert_equal TimeSubclass, TimeSubclass.now.class + assert_equal DateSubclass, DateSubclass.today.class + assert_equal DateTimeSubclass, DateTimeSubclass.now.class + + travel 1.day do + assert_equal TimeSubclass, TimeSubclass.now.class + assert_equal DateSubclass, DateSubclass.today.class + assert_equal DateTimeSubclass, DateTimeSubclass.now.class + assert_equal Time.now.to_s, TimeSubclass.now.to_s + assert_equal Date.today.to_s, DateSubclass.today.to_s + assert_equal DateTime.now.to_s, DateTimeSubclass.now.to_s + end + end end |