Commit Graph

37 Commits

Author SHA1 Message Date
Jean Boussier
aa84a783ee ruby-head: handle unused block warnings
Ref: https://bugs.ruby-lang.org/issues/15554

This new Ruby 3.4 warning is still being fined tuned to reduce false positives,
so we shouldn't fail builds on it just yet.

It however caught one mistake in the test suite which is valuable.
2024-04-17 12:24:12 +02:00
Aleksei Chernenkov
aedb808829 Fix Time.now/DateTime.now/Date.today to return results in a system timezone after #travel_to
There is a bug in the current implementation of #travel_to:
it remembers a timezone of its argument, and all stubbed methods start
returning results in that remembered timezone. However, the expected
behaviour is to return results in a system timezone.

It can lead to bugs in tests like this one:
https://github.com/faker-ruby/faker/issues/2861
2023-12-02 10:05:31 +01:00
fatkodima
7fd26579c0 Fix time travel helpers to work when nested using with separate classes 2023-10-20 02:46:42 +03:00
Nikita Vasilevsky
19f8ab2e7d
[Tests only] Enable Minitest/AssertPredicate rule 2023-10-13 19:26:47 +00:00
fatkodima
0c4e9d35bb Stub Time.new() in TimeHelpers#travel_to 2023-02-14 11:28:52 +02:00
Philip Dubé
499e9dc737 TimeHelpers: include with_usec keyword parameter on travel & freeze too 2022-12-14 15:20:40 +00:00
David Heinemeier Hansson
41478f7074 Make #to_fs the default replacement for #to_s(:format)
#to_formatted_s is too cumbersome.
2022-02-07 12:41:21 +01:00
Kev
0ab5a3a4ab Allow subsecond resolution in travel_to helper
The `travel_to` helper didn’t support subsecond time traveling in order
to prevent problems with external services, such as MySQL. This,
however, makes it impossible to test features that use durations less
than a second ("subsecond").

This therefore allows `travel_to` to stub `Time.now` with the accurate
time passed to it as `date_or_time` if the `with_usec` optional argument
is set to true:

    Time.now.inspect # => 2022-01-05 22:36:54.613371959 +0000
    travel_to(0.1.seconds.from_now, with_usec: true)
    Time.now.inspect # => 2022-01-05 22:36:54.713371959 +0000
2022-01-06 00:53:35 +01:00
Rafael Mendonça França
c2e12e0191
Use to_formatted_s(:db) instead of to_s(:db) internally
Ruby 3.1 introduced an optimization to string interpolation for some
core classes in b08dacfea3.

But since we override `to_s` in some of those core classes to add behavior
like `to_s(:db)`, all Rails applications will not be able to take advantage
of that improvement.

Since we can use the `to_formatted_s` alias for the Rails specific behavior
it is best for us to deprecate the `to_s` core extension and allow Rails
applications to get the proformace improvement.

This commit starts removing all the `to_s(:db)` calls inside the framework
so we can deprecate the core extension in the next commit.
2021-12-06 19:22:04 +00:00
Christian Schmidt
7e6dd6b21f Travel back after block 2021-06-08 16:54:42 +02:00
Christian Schmidt
a829bb7639 Allow travel blocks after standalone travelt 2021-06-05 15:58:41 +02:00
alvir
b96f4ae1d5 Use application time zone when gets time as String. 2020-11-26 11:35:23 +03:00
Ian Fleeton
684ae07e2f Don't encourage using octals for dates and times
This could result in confusing errors or inconsistency for 08 and 09
2020-01-15 10:57:38 +00:00
Michael Grosser
203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00
Tim Masliuchenko
21f907bb51
Accept block in travel_back time helper 2019-11-10 20:02:09 +01:00
alkesh26
38472af70e ActiveSupport typo fixes. 2019-02-01 22:17:10 +05:30
Ryuta Kamizono
b75192845a
Merge pull request #34764 from kamipo/avoid_redundant_begin
Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
2018-12-21 17:36:30 +09:00
yuuji.yaginuma
5d905abbe7 Add test for travel_to with time zone
This is a regression test for #34751.
2018-12-21 10:08:33 +09:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
ryanwhocodes
36e6571a40 Add #unfreeze_time to ActiveSupport::Testing::TimeHelpers 2018-09-10 22:32:41 +01:00
Ryuta Kamizono
245c1dafa8 Enable Layout/LeadingCommentSpace to not allow cosmetic changes in the future
Follow up of #31432.
2017-12-14 17:30:54 +09:00
Koichi ITO
ac717d65a3 [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
प्रथमेश Sonpatki
b6300f3ecc Added time helper method freeze_time which is an alias for travel_to Time.now (#29681) 2017-07-10 12:13:37 +02:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Ryuta Kamizono
b201474756 Should escape meta characters in regexp 2017-05-07 04:10:00 +09:00
yuuji.yaginuma
c42bd31977 correctly check error message
`assert_raise` does not check error message. However, in some tests,
it seems like expecting error message checking with `assert_raise`.
Instead of specifying an error message in `assert_raise`, modify to use
another assert to check the error message.
2017-01-25 09:58:15 +09:00
Jonas Nicklas
3d78949c74 Make time travel work with subclasses of Time/Date/Datetime
Closes #27614

Previously when calling `now` on a subclass of e.g. `Time` it would return an instance of `Time` instead of returning an instance of the subclass. This way, we always return the correct class.
2017-01-10 11:43:26 +01:00
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Rafael Mendonça França
bbbabc22c1
Make sure the time method is unstubed
The minitest stubs were conflicting with the time travel stubs so the
travel_back method call in the teardown block was actually keeping the
time stubbed.
2016-07-17 05:13:20 -03:00
Vipul A M
919e705362
travel/travel_to travel time helpers, now raise on nested calls,
as this can lead to confusing time stubbing.

     Instead of:

         travel_to 2.days.from_now do
           # 2 days from today
           travel_to 3.days.from_now do
             # 5 days from today
           end
         end

     preferred way to achieve above is:

         travel_to 2.days.from_now
         # 2 days from today

         travel_back
         travel_to 5.days.from_now
         # 5 days from today

Closes #24690
Fixes #24689
2016-07-02 15:09:34 -07:00
Ronak Jangir
81d2ce96d0 Removed mocha stubbing in active_support 2015-06-07 19:18:58 +05:30
Ankit Gupta
40fe833493 as/core_ext require's not used 2015-05-08 10:39:30 -04:00
Yuki Nishijima
a57ddc58ac Change AS::Testing::TimeHelpers#travel_to to also stub DateTime.now 2015-02-03 05:23:23 -08:00
Zachary Scott
a5d50ac147 Move date and time requires to time_travel_test, also include
'abstract_unit'.

cc #16564
2014-08-19 13:17:23 -07:00
Zachary Scott
ab291e8718 Move TimeHelperTest to TimeTravelTest from as/test_test.rb 2014-08-19 11:29:26 -07:00