diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2017-01-12 07:20:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-12 07:20:28 +0000 |
commit | 033f6540270ea84e7579a585c657ed2c3bcf0ee0 (patch) | |
tree | fd58e999e3e198742b76a38f7b848eb0d7f4349e /activesupport/test | |
parent | 37f889b4a2d8862fb7c6939e5bd6be5897a587b1 (diff) | |
parent | cb9d0e4864fa68fad9c49b880c32e90ddf0545bd (diff) | |
download | rails-033f6540270ea84e7579a585c657ed2c3bcf0ee0.tar.gz rails-033f6540270ea84e7579a585c657ed2c3bcf0ee0.tar.bz2 rails-033f6540270ea84e7579a585c657ed2c3bcf0ee0.zip |
Merge pull request #27610 from Envek/fix_and_speed_up_duration_parsing
Fix inconsistent parsing of Durations with both months and years
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 1 | ||||
-rw-r--r-- | activesupport/test/core_ext/numeric_ext_test.rb | 10 |
2 files changed, 6 insertions, 5 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index fc0dd41d0e..8c4c08ffd4 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -340,6 +340,7 @@ class DurationTest < ActiveSupport::TestCase travel_to Time.utc(2016, 11, 4) do assert_equal 604800, ActiveSupport::Duration.parse("P7D").to_i assert_equal 604800, ActiveSupport::Duration.parse("P1W").to_i + assert_equal ActiveSupport::Duration.parse(3.years.iso8601).to_i, 3.years.to_i end end end diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 5361b7b708..5f86bf97c8 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -12,7 +12,7 @@ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase 10.minutes => 600, 1.hour + 15.minutes => 4500, 2.days + 4.hours + 30.minutes => 189000, - 5.years + 1.month + 1.fortnight => 161589600 + 5.years + 1.month + 1.fortnight => 161624106 } end @@ -61,10 +61,10 @@ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase end def test_duration_after_conversion_is_no_longer_accurate - assert_equal 30.days.to_i.seconds.since(@now), 1.month.to_i.seconds.since(@now) - assert_equal 365.25.days.to_f.seconds.since(@now), 1.year.to_f.seconds.since(@now) - assert_equal 30.days.to_i.seconds.since(@dtnow), 1.month.to_i.seconds.since(@dtnow) - assert_equal 365.25.days.to_f.seconds.since(@dtnow), 1.year.to_f.seconds.since(@dtnow) + assert_equal (1.year / 12).to_i.seconds.since(@now), 1.month.to_i.seconds.since(@now) + assert_equal 365.2425.days.to_f.seconds.since(@now), 1.year.to_f.seconds.since(@now) + assert_equal (1.year / 12).to_i.seconds.since(@dtnow), 1.month.to_i.seconds.since(@dtnow) + assert_equal 365.2425.days.to_f.seconds.since(@dtnow), 1.year.to_f.seconds.since(@dtnow) end def test_add_one_year_to_leap_day |