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

Projects
None yet
4 participants
@prathamesh-sonpatki
Member

prathamesh-sonpatki commented Jul 5, 2017

r? @dhh

Show outdated Hide outdated activesupport/lib/active_support/testing/time_helpers.rb
# 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 ...

@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

Member

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

@prathamesh-sonpatki

prathamesh-sonpatki Jul 5, 2017

Member

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

Show outdated Hide outdated activesupport/lib/active_support/testing/time_helpers.rb
# 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.

@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

Member

@dhh Added support for block as well.

@prathamesh-sonpatki

prathamesh-sonpatki Jul 9, 2017

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.

@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

Member

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

@prathamesh-sonpatki

prathamesh-sonpatki Jul 9, 2017

Member

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

@dhh

This comment has been minimized.

Show comment
Hide comment
@dhh

dhh Jul 10, 2017

Member

Excellent, thanks!

Member

dhh commented Jul 10, 2017

Excellent, thanks!

@dhh dhh merged commit b6300f3 into rails:master Jul 10, 2017

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

chovaism added a commit to chovaism/rails that referenced this pull request Jul 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment