aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/time_helpers.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #17302 from ↵Rafael Mendonça França2014-10-181-2/+2
| | | | | | claudiob/replace-slower-block-call-with-faster-yield Replace (slower) block.call with (faster) yield
* Revert "Replace (slower) block.call with (faster) yield"Zachary Scott2014-10-181-2/+2
| | | | This reverts commit 0ab075e75f58bf403f7ebe20546c7005f35db1f6.
* Replace (slower) block.call with (faster) yieldclaudiob2014-10-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Performance optimization: `yield` with an implicit `block` is faster than `block.call`. See http://youtu.be/fGFM_UrSp70?t=10m35s and the following benchmark: ```ruby require 'benchmark/ips' def fast yield end def slow(&block) block.call end Benchmark.ips do |x| x.report('fast') { fast{} } x.report('slow') { slow{} } end # => fast 154095 i/100ms # => slow 71454 i/100ms # => # => fast 7511067.8 (±5.0%) i/s - 37445085 in 4.999660s # => slow 1227576.9 (±6.8%) i/s - 6145044 in 5.028356s ```
* Fix rounding errors with #travel_to by resetting the usec on any passed time ↵David Heinemeier Hansson2014-08-171-1/+5
| | | | to zero, so we only travel with per-second precision, not anything deeper than that.
* 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.