From 1f1613604925823be4b15893fbb8f957a38dd0b8 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 27 Sep 2013 12:51:36 -0700 Subject: Deprecated Numeric#{ago,until,since,from_now} 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. --- activesupport/CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activesupport/CHANGELOG.md') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 104b5eafa1..d03b1674d4 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,20 @@ +* Deprecated Numeric#{ago,until,since,from_now}, 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. + + *Godfrey Chan* + * Add `ActiveSupport::Testing::TimeHelpers#travel` and `#travel_to`. These methods change current time to the given time or time difference by stubbing `Time.now` and `Date.today` to return the time or date after the difference calculation, or the time or date that got passed into the -- cgit v1.2.3