Skip to content

Commit

Permalink
Fixed errors thrown to namespace collision
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@421 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jan 15, 2005
1 parent 2aac6d9 commit 31901a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions activesupport/lib/core_ext/numeric/time.rb
Expand Up @@ -38,15 +38,15 @@ def years
alias :year :years alias :year :years


# Reads best without arguments: 10.minutes.ago # Reads best without arguments: 10.minutes.ago
def ago(time = Time.now) def ago(time = ::Time.now)
time - self time - self
end end


# Reads best with argument: 10.minutes.until(time) # Reads best with argument: 10.minutes.until(time)
alias :until :ago alias :until :ago


# Reads best with argument: 10.minutes.since(time) # Reads best with argument: 10.minutes.since(time)
def since(time = Time.now) def since(time = ::Time.now)
time + self time + self
end end


Expand Down
22 changes: 18 additions & 4 deletions activesupport/test/core_ext/numeric_ext_test.rb
Expand Up @@ -13,17 +13,31 @@ def setup
} }
end end


def test_time_units def test_units
@seconds.each do |actual, expected| @seconds.each do |actual, expected|
assert_equal expected, actual assert_equal expected, actual
assert_equal expected.since(@now), @now + actual end
assert_equal expected.until(@now), @now - actual 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 end
end end


class NumericExtSizeTest < Test::Unit::TestCase class NumericExtSizeTest < Test::Unit::TestCase

def test_unit_in_terms_of_another def test_unit_in_terms_of_another
relationships = { relationships = {
1024.kilobytes => 1.megabyte, 1024.kilobytes => 1.megabyte,
Expand Down

0 comments on commit 31901a5

Please sign in to comment.