aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/time_helpers.rb
Commit message (Collapse)AuthorAgeFilesLines
* travel_to travels back and re-raises if the block raisesXavier Noria2014-02-181-3/+6
|
* time helpers honor the application time zone when passed a dateXavier Noria2014-02-181-4/+19
| | | | | | | | | | | | | | | | | Rails applications are expected to be always aware of the application time zone. To be consistent with that contract, we have to assume that a bare date passed to time helpers is a date in the application time zone, not in the system time zone. The system time zone is irrelevant, we should totally ignore it. For example, travel_to user.birth_date + 40.years should make that user be 40th years old regardless of the system time zone. Without this patch that may not be true.
* Improve documentation [ci skip]Rafael Mendonça França2014-01-301-3/+4
|
* Remove automatic removal of Date/Time stubs after each test caseRafael Mendonça França2014-01-301-9/+2
| | | | | | This behavior is only work out-of-box with minitest and also add a downside to run after each test case, even if we don't used the travel or travel_to methods
* Add `travel_back` to remove stubs from `travel` and `travel_to`Rafael Mendonça França2014-01-301-3/+14
|
* Use each_valueRafael Mendonça França2014-01-291-1/+1
|
* Store the singleton_class in a local variableRafael Mendonça França2014-01-291-3/+4
|
* Change the class and method visibilityRafael Mendonça França2014-01-291-9/+13
|
* Use instance method instead of before hookRafael Mendonça França2014-01-291-9/+8
|
* Alias the original method first to avoid warningsRafael Mendonça França2014-01-291-2/+7
|
* Implement a simple stub feature to use in the Time travel helpersRafael Mendonça França2014-01-291-4/+44
|
* doc `travel` and `travel_to` stubs are removed in teardown. [ci skip]Yves Senn2013-11-211-4/+4
|
* Add `#travel` and `#travel_to` to AS::TestCasePrem Sichanugrist2013-11-201-0/+55
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 method respectively. These methods also accept a block, which will return current time back to its original state at the end of the block. Example for `#travel`: Time.now # => 2013-11-09 15:34:49 -05:00 travel 1.day Time.now # => 2013-11-10 15:34:49 -05:00 Date.today # => Sun, 10 Nov 2013 Example for `#travel_to`: Time.now # => 2013-11-09 15:34:49 -05:00 travel_to Time.new(2004, 11, 24, 01, 04, 44) Time.now # => 2004-11-24 01:04:44 -05:00 Date.today # => Wed, 24 Nov 2004 Both of these methods also accept a block, which will return the current time back to its original state at the end of the block: Time.now # => 2013-11-09 15:34:49 -05:00 travel 1.day do User.create.created_at # => Sun, 10 Nov 2013 15:34:49 EST -05:00 end travel_to Time.new(2004, 11, 24, 01, 04, 44) do User.create.created_at # => Wed, 24 Nov 2004 01:04:44 EST -05:00 end Time.now # => 2013-11-09 15:34:49 -05:00 This module is included in `ActiveSupport::TestCase` automatically.