diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/core_ext/numeric/time.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/numeric_ext_test.rb | 22 |
2 files changed, 20 insertions, 6 deletions
diff --git a/activesupport/lib/core_ext/numeric/time.rb b/activesupport/lib/core_ext/numeric/time.rb index 850dc9a783..ac5ecb8b70 100644 --- a/activesupport/lib/core_ext/numeric/time.rb +++ b/activesupport/lib/core_ext/numeric/time.rb @@ -38,7 +38,7 @@ module ActiveSupport alias :year :years # Reads best without arguments: 10.minutes.ago - def ago(time = Time.now) + def ago(time = ::Time.now) time - self end @@ -46,7 +46,7 @@ module ActiveSupport alias :until :ago # Reads best with argument: 10.minutes.since(time) - def since(time = Time.now) + def since(time = ::Time.now) time + self end diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 6057c8f8c3..a83c472b84 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -13,17 +13,31 @@ class NumericExtTimeTest < Test::Unit::TestCase } end - def test_time_units + def test_units @seconds.each do |actual, expected| assert_equal expected, actual - assert_equal expected.since(@now), @now + actual - assert_equal expected.until(@now), @now - actual + end + end + + def test_intervals + @seconds.values.each do |seconds| + assert_equal seconds.since(@now), @now + seconds + assert_equal seconds.until(@now), @now - seconds + end + end + + # Test intervals based from Time.now + def test_now + @seconds.values.each do |seconds| + now = Time.now + assert seconds.ago >= now - seconds + now = Time.now + assert seconds.from_now >= now + seconds end end end class NumericExtSizeTest < Test::Unit::TestCase - def test_unit_in_terms_of_another relationships = { 1024.kilobytes => 1.megabyte, |