Deprecated Numeric#{ago,until,since,from_now}#12389
Merged
Merged
Conversation
Member
There was a problem hiding this comment.
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.
Member
There was a problem hiding this comment.
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."
Member
Author
|
@jeremy I trimmed this down to an MVP / Minimal Viable Pull-request. Doubts-- ? 😁 |
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.
Member
Author
|
Rebased to keep it fresh :) Probably would have to do it again when someone is ready to merge this, stupid CHANGELOGs |
Member
|
Merged d4016f2 |
This was referenced Dec 4, 2013
chancancode
added a commit
that referenced
this pull request
May 30, 2014
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.
jrafanie
added a commit
to tenderlove/manageiq
that referenced
this pull request
Jan 8, 2015
Fixes: undefined method `from_now' for 600:Fixnum See also: rails/rails#12389
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The user is expected to explicitly convert the value into an AS::Duration, i.e.
5.ago=>5.seconds.agoThis 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 fromNumerictoAS::Duration./cc @jeremy @sikachu