aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/time_helpers.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-29 22:24:48 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-30 10:17:47 -0200
commit6b16c2788186d45c70bd1d9fc476407e3e265439 (patch)
treedb7b781e5e1579ce703feb75f5f42abd08fce344 /activesupport/lib/active_support/testing/time_helpers.rb
parent7f5466d58299db35a3d320e0b526001ae3be11a7 (diff)
downloadrails-6b16c2788186d45c70bd1d9fc476407e3e265439.tar.gz
rails-6b16c2788186d45c70bd1d9fc476407e3e265439.tar.bz2
rails-6b16c2788186d45c70bd1d9fc476407e3e265439.zip
Add `travel_back` to remove stubs from `travel` and `travel_to`
Diffstat (limited to 'activesupport/lib/active_support/testing/time_helpers.rb')
-rw-r--r--activesupport/lib/active_support/testing/time_helpers.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb
index 0ee6332d6f..b183b8d8ef 100644
--- a/activesupport/lib/active_support/testing/time_helpers.rb
+++ b/activesupport/lib/active_support/testing/time_helpers.rb
@@ -42,7 +42,7 @@ module ActiveSupport
# Containing helpers that helps you test passage of time.
module TimeHelpers
def after_teardown #:nodoc:
- simple_stubs.unstub_all!
+ travel_back
super
end
@@ -81,7 +81,7 @@ module ActiveSupport
#
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
# 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
+ # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
# end
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
def travel_to(date_or_time, &block)
@@ -90,10 +90,21 @@ module ActiveSupport
if block_given?
block.call
- simple_stubs.unstub_all!
+ travel_back
end
end
+ # Return the current time back to its original state.
+ #
+ # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
+ # travel_to Time.new(2004, 11, 24, 01, 04, 44)
+ # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
+ # travel_back
+ # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
+ def travel_back
+ simple_stubs.unstub_all!
+ end
+
private
def simple_stubs