Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added time helper method `freeze_time` which is an alias for `travel_to Time.now` #29681

Merged
merged 1 commit into from Jul 10, 2017

Conversation

@prathamesh-sonpatki
Copy link
Member

@prathamesh-sonpatki prathamesh-sonpatki commented Jul 5, 2017

r? @dhh

activesupport/lib/active_support/testing/time_helpers.rb Outdated
# Time.now # => 2017-07-05 11:01:38 +0530
# Time.now # => 2017-07-05 11:01:38 +0530
def freeze_time
travel_to Time.now

This comment has been minimized.

@sikachu

sikachu Jul 5, 2017
Member

Shouldn't this be Time.current though, just so we can take Time.zone into account?

I wonder if it matters ...

This comment has been minimized.

@prathamesh-sonpatki

prathamesh-sonpatki Jul 5, 2017
Author Member

I went by the existing definition of travel method which uses Time.now.

activesupport/lib/active_support/testing/time_helpers.rb Outdated
# freeze_time
# Time.now # => 2017-07-05 11:01:38 +0530
# Time.now # => 2017-07-05 11:01:38 +0530
def freeze_time

This comment has been minimized.

@dhh

dhh Jul 5, 2017
Member

Would be nice if this also worked with a block, like travel does.

This comment has been minimized.

@prathamesh-sonpatki

prathamesh-sonpatki Jul 9, 2017
Author Member

@dhh Added support for block as well.

@@ -162,4 +162,13 @@ def test_time_helper_travel_with_time_subclass
assert_equal DateTime.now.to_s, DateTimeSubclass.now.to_s
end
end

def test_time_helper_freeze_time

This comment has been minimized.

@meinac

meinac Jul 5, 2017
Contributor

This is not a deterministic test. This can still pass without the correct implementation, you can get same formatted time 3 times.

This comment has been minimized.

@prathamesh-sonpatki

prathamesh-sonpatki Jul 9, 2017
Author Member

Yup, updated the test to be non-deterministic. Please check.

@prathamesh-sonpatki prathamesh-sonpatki force-pushed the prathamesh-sonpatki:freeze-time branch 2 times, most recently Jul 9, 2017
…to Time.now`
@prathamesh-sonpatki prathamesh-sonpatki force-pushed the prathamesh-sonpatki:freeze-time branch to 248749f Jul 9, 2017
@dhh
Copy link
Member

@dhh dhh commented Jul 10, 2017

Excellent, thanks!

@dhh dhh merged commit b6300f3 into rails:master Jul 10, 2017
2 checks passed
2 checks passed
codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@prathamesh-sonpatki prathamesh-sonpatki deleted the prathamesh-sonpatki:freeze-time branch Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.