diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2017-07-27 14:59:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-27 14:59:43 +0100 |
commit | 566c2c4498cc88cae3f1a999e4cb49f836e89efb (patch) | |
tree | dee04e8a7abaf285aa0181240aa43f58419e4d94 /activesupport/test/core_ext/duration_test.rb | |
parent | 4caf751fffcd0d25b563bd5fd13fc075560aa8d5 (diff) | |
parent | bfa878d3b2a814db4d781143c9f5248b642900d0 (diff) | |
download | rails-566c2c4498cc88cae3f1a999e4cb49f836e89efb.tar.gz rails-566c2c4498cc88cae3f1a999e4cb49f836e89efb.tar.bz2 rails-566c2c4498cc88cae3f1a999e4cb49f836e89efb.zip |
Merge pull request #29971 from rails/fix-duration-division
Fix division where a duration is the denominator
Diffstat (limited to 'activesupport/test/core_ext/duration_test.rb')
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index c655f466f2..1d607a20a6 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -410,9 +410,11 @@ class DurationTest < ActiveSupport::TestCase assert_equal 5, scalar / 2 assert_instance_of ActiveSupport::Duration::Scalar, scalar / 2 assert_equal 10, 100.seconds / scalar + assert_instance_of ActiveSupport::Duration, 100.seconds / scalar + assert_equal 20, 2.seconds * scalar assert_instance_of ActiveSupport::Duration, 2.seconds * scalar assert_equal 5, scalar / 2.seconds - assert_instance_of ActiveSupport::Duration, scalar / 2.seconds + assert_kind_of Integer, scalar / 2.seconds exception = assert_raises(TypeError) do scalar / "foo" @@ -421,15 +423,6 @@ class DurationTest < ActiveSupport::TestCase assert_equal "no implicit conversion of String into ActiveSupport::Duration::Scalar", exception.message end - def test_scalar_divide_parts - scalar = ActiveSupport::Duration::Scalar.new(10) - - assert_equal({ days: 2 }, (scalar / 5.days).parts) - assert_equal(172800, (scalar / 5.days).value) - assert_equal({ days: -2 }, (scalar / -5.days).parts) - assert_equal(-172800, (scalar / -5.days).value) - end - def test_twelve_months_equals_one_year assert_equal 12.months, 1.year end @@ -438,6 +431,17 @@ class DurationTest < ActiveSupport::TestCase assert_not_equal 30.days, 1.month end + def test_division + assert_equal 1.hour, 1.day / 24 + assert_instance_of ActiveSupport::Duration, 1.day / 24 + + assert_equal 24, 86400 / 1.hour + assert_kind_of Integer, 86400 / 1.hour + + assert_equal 24, 1.day / 1.hour + assert_kind_of Integer, 1.day / 1.hour + end + def test_adding_one_month_maintains_day_of_month (1..11).each do |month| [1, 14, 28].each do |day| |