-
Notifications
You must be signed in to change notification settings - Fork 21.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecated Numeric#{ago,until,since,from_now} #12389
Conversation
@@ -1,3 +1,7 @@ | |||
* Deprecated Numeric#{ago,until,since,from_now}, use 5.seconds.ago instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request description is so clear and understandable, but this just describes the diff. Think of the Rails dev reviewing the CHANGELOG to see what's changed and why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 😁
@@ -63,7 +63,8 @@ def fortnights | |||
|
|||
# Reads best without arguments: 10.minutes.ago | |||
def ago(time = ::Time.current) | |||
time - self | |||
ActiveSupport::Deprecation.warn "Numeric#ago (#{self.to_s}.ago) is deprecated and will be removed in the future, use #{self.to_s}.seconds.ago instead" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to say Numeric#ago (2013-09-27 14:36:52 -0700.ago) is deprecated ...
which doesn't make sense. Consider something like: "Calling the #ago method on a number, like 5.ago, is deprecated in favor of calling it on a duration, like 5.seconds.ago."
@jeremy I trimmed this down to an MVP / Minimal Viable Pull-request. Doubts-- ? 😁 |
@@ -63,6 +63,7 @@ def fortnights | |||
|
|||
# Reads best without arguments: 10.minutes.ago | |||
def ago(time = ::Time.current) | |||
ActiveSupport::Deprecation.warn "Calling #ago or #until on a nunmber (e.g. 5.ago) is deprecated and will be removed in the future, use 5.seconds.ago instead" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nunmber -> number
The user is expected to explicitly convert the value into an AS::Duration, i.e. `5.ago` => `5.seconds.ago` This will help to catch subtle bugs like: def recent?(days = 3) self.created_at >= days.ago end The above code would check if the model is created within the last 3 **seconds**. In the future, `Numeric#{ago,until,since,from_now}` should be removed completely, or throw some sort of errors to indicate there are no implicit conversion from `Numeric` to `AS::Duration`. Also fixed & refactor the test cases for Numeric#{ago,since} and AS::Duration#{ago,since}. The original test case had the assertion flipped and the purpose of the test wasn't very clear.
Rebased to keep it fresh :) Probably would have to do it again when someone is ready to merge this, stupid CHANGELOGs |
Merged d4016f2 |
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.
Fixes: undefined method `from_now' for 600:Fixnum See also: rails/rails#12389
The user is expected to explicitly convert the value into an AS::Duration, i.e.
5.ago
=>5.seconds.ago
This will help to catch subtle bugs like:
The above code would check if the model is created within the last 3 seconds.
In the future,
Numeric#{ago,until,since,from_now}
should be removed completely, or throw some sort of errors to indicate there are no implicit conversion fromNumeric
toAS::Duration
./cc @jeremy @sikachu