mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
✂️ removed deprecated Numeric#ago
and friends
Replacements: 5.ago => 5.seconds.ago 5.until => 5.seconds.until 5.since => 5.seconds.since 5.from_now => 5.seconds.from_now The removed tests does not affect coverage – we have equivalent test cases in the tests for `AS::Duration`. See #12389 for the history and rationale behind this.
This commit is contained in:
parent
58d3e02579
commit
f1eddea1e3
3 changed files with 15 additions and 62 deletions
|
@ -1,3 +1,16 @@
|
|||
* Removed deprecated `Numeric#ago` and friends
|
||||
|
||||
Replacements:
|
||||
|
||||
5.ago => 5.seconds.ago
|
||||
5.until => 5.seconds.until
|
||||
5.since => 5.seconds.since
|
||||
5.from_now => 5.seconds.from_now
|
||||
|
||||
See #12389 for the history and rationale behind this.
|
||||
|
||||
*Godfrey Chan*
|
||||
|
||||
* DateTime `advance` now supports partial days.
|
||||
|
||||
Before:
|
||||
|
|
|
@ -61,25 +61,7 @@ class Numeric
|
|||
end
|
||||
alias :fortnight :fortnights
|
||||
|
||||
# Reads best without arguments: 10.minutes.ago
|
||||
def ago(time = ::Time.current)
|
||||
ActiveSupport::Deprecation.warn "Calling #ago or #until on a number (e.g. 5.ago) is deprecated and will be removed in the future, use 5.seconds.ago instead"
|
||||
time - self
|
||||
end
|
||||
|
||||
# Reads best with argument: 10.minutes.until(time)
|
||||
alias :until :ago
|
||||
|
||||
# Reads best with argument: 10.minutes.since(time)
|
||||
def since(time = ::Time.current)
|
||||
ActiveSupport::Deprecation.warn "Calling #since or #from_now on a number (e.g. 5.since) is deprecated and will be removed in the future, use 5.seconds.since instead"
|
||||
time + self
|
||||
end
|
||||
|
||||
# Reads best without arguments: 10.minutes.from_now
|
||||
alias :from_now :since
|
||||
|
||||
# Used with the standard time durations, like 1.hour.in_milliseconds --
|
||||
# Used with the standard time durations, like 1.hour.in_milliseconds --
|
||||
# so we can feed them to JavaScript functions like getTime().
|
||||
def in_milliseconds
|
||||
self * 1000
|
||||
|
|
|
@ -22,18 +22,6 @@ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_deprecated_since_and_ago
|
||||
assert_equal @now + 1, assert_deprecated { 1.since(@now) }
|
||||
assert_equal @now - 1, assert_deprecated { 1.ago(@now) }
|
||||
end
|
||||
|
||||
def test_deprecated_since_and_ago_without_argument
|
||||
now = Time.now
|
||||
assert assert_deprecated { 1.since } >= now + 1
|
||||
now = Time.now
|
||||
assert assert_deprecated { 1.ago } >= now - 1
|
||||
end
|
||||
|
||||
def test_irregular_durations
|
||||
assert_equal @now.advance(:days => 3000), 3000.days.since(@now)
|
||||
assert_equal @now.advance(:months => 1), 1.month.since(@now)
|
||||
|
@ -84,36 +72,6 @@ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase
|
|||
assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10) + 1.year
|
||||
end
|
||||
|
||||
def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set
|
||||
Time.zone = nil
|
||||
with_env_tz 'US/Eastern' do
|
||||
Time.stubs(:now).returns Time.local(2000)
|
||||
# since
|
||||
assert_not_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.since }
|
||||
assert_equal Time.local(2000,1,1,0,0,5), assert_deprecated { 5.since }
|
||||
# ago
|
||||
assert_not_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.ago }
|
||||
assert_equal Time.local(1999,12,31,23,59,55), assert_deprecated { 5.ago }
|
||||
end
|
||||
end
|
||||
|
||||
def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
|
||||
Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
||||
with_env_tz 'US/Eastern' do
|
||||
Time.stubs(:now).returns Time.local(2000)
|
||||
# since
|
||||
assert_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.since }
|
||||
assert_equal Time.utc(2000,1,1,0,0,5), assert_deprecated { 5.since.time }
|
||||
assert_equal 'Eastern Time (US & Canada)', assert_deprecated { 5.since.time_zone.name }
|
||||
# ago
|
||||
assert_instance_of ActiveSupport::TimeWithZone, assert_deprecated { 5.ago }
|
||||
assert_equal Time.utc(1999,12,31,23,59,55), assert_deprecated { 5.ago.time }
|
||||
assert_equal 'Eastern Time (US & Canada)', assert_deprecated { 5.ago.time_zone.name }
|
||||
end
|
||||
ensure
|
||||
Time.zone = nil
|
||||
end
|
||||
|
||||
protected
|
||||
def with_env_tz(new_tz = 'US/Eastern')
|
||||
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
||||
|
@ -435,7 +393,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
|
|||
assert_equal BigDecimal, BigDecimal("1000010").class
|
||||
assert_equal '1 Million', BigDecimal("1000010").to_s(:human)
|
||||
end
|
||||
|
||||
|
||||
def test_in_milliseconds
|
||||
assert_equal 10_000, 10.seconds.in_milliseconds
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue