diff options
author | Jonathan del Strother <jdelStrother@gmail.com> | 2018-02-07 13:06:11 +0000 |
---|---|---|
committer | Jonathan del Strother <jdelStrother@gmail.com> | 2018-02-07 13:19:08 +0000 |
commit | a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25 (patch) | |
tree | 6898ee3324b1ed2cd658c44d14649abc237de952 /activesupport/test | |
parent | 2c0300389c3f6be00bf6c6b806332808a9400429 (diff) | |
download | rails-a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25.tar.gz rails-a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25.tar.bz2 rails-a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25.zip |
Fix yaml deserialization of ActiveSupport::Duration
This ensures the duration's @parts hash has a default value, to avoid this regression introduced in 5.1:
YAML.load(YAML.dump(10.minutes)) + 1 # => NoMethodError: undefined method `+' for nil:NilClass
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index cd1b505c34..6366db99dc 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -585,6 +585,12 @@ class DurationTest < ActiveSupport::TestCase assert_equal time + d1, time + d2 end + def test_durations_survive_yaml_serialization + d1 = YAML.load(YAML.dump(10.minutes)) + assert_equal 600, d1.to_i + assert_equal 660, (d1 + 60).to_i + end + private def eastern_time_zone if Gem.win_platform? |