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

Add new Rails/FreezeTime cop #714

Merged
merged 1 commit into from Jul 18, 2022
Merged

Conversation

ydah
Copy link
Member

@ydah ydah commented Jun 14, 2022

Refs: https://github.com/rubocop/rails-style-guide#freeze_time

This cop Identifies usages of travel_to with argument current time and
change them to use freeze_time instead.

@example

# bad
travel_to(Time.now)
travel_to(DateTime.now)
travel_to(Time.current)
travel_to(Time.zone.now)
travel_to(Time.now.in_time_zone)
travel_to(Time.current.to_time)

# good
freeze_time

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • [-] Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@ydah ydah force-pushed the add_new_rails_freeze_time branch 2 times, most recently from 904a814 to d81f242 Compare June 14, 2022 09:22
@ydah ydah marked this pull request as ready for review June 14, 2022 09:25
@koic
Copy link
Member

koic commented Jun 14, 2022

If this is a new cop, consider making a corresponding update to the Rails Style Guide.

Can you open it to the Rails Style Guide first?

config/default.yml Outdated Show resolved Hide resolved
@ydah ydah force-pushed the add_new_rails_freeze_time branch from d81f242 to 2f68140 Compare June 14, 2022 13:46
@ydah
Copy link
Member Author

ydah commented Jun 15, 2022

The freeze_time description mentioned in this PR has been merged into the Rails Style Guide.
Sorry for the back and forth.

https://github.com/rubocop/rails-style-guide#freeze_time

@ydah ydah force-pushed the add_new_rails_freeze_time branch 2 times, most recently from 05e8d69 to 339a7f5 Compare June 15, 2022 08:35
@ydah ydah requested a review from koic June 15, 2022 08:36
@nekonenene
Copy link

Even if we adopt this pull request, I thought it would be appropriate to merge it into https://github.com/rubocop/rubocop-rspec .

@koic
Copy link
Member

koic commented Jun 15, 2022

Even if we adopt this pull request, I thought it would be appropriate to merge it into https://github.com/rubocop/rubocop-rspec .

The testing framework provided by Rails core is ActiveSupport::TestCase based on Minitest. Not RSpec. travel_to and freeze_time methods are provided by ActiveSupport, so this cop would be better placed in this rubocop-rails.

@nekonenene
Copy link

I see. I made a mistake because it is related to the test, but you're right!

@ydah ydah force-pushed the add_new_rails_freeze_time branch from 339a7f5 to 792357e Compare June 16, 2022 00:14
@ydah ydah force-pushed the add_new_rails_freeze_time branch 2 times, most recently from 0b08ba6 to f60e663 Compare June 23, 2022 10:09
@ydah ydah requested a review from koic June 23, 2022 11:11
Refs: https://github.com/rubocop/rails-style-guide#freeze_time

This cop Identifies usages of `travel_to` with argument current time and
change them to use `freeze_time` instead.

@example
```ruby
# bad
travel_to(Time.now)
travel_to(DateTime.now)
travel_to(Time.current)
travel_to(Time.zone.now)
travel_to(Time.now.in_time_zone)
travel_to(Time.current.to_time)

# good
freeze_time
```
@ydah ydah force-pushed the add_new_rails_freeze_time branch from f60e663 to 8bedc3f Compare July 16, 2022 22:45
@koic koic merged commit 0610d73 into rubocop:master Jul 18, 2022
@koic
Copy link
Member

koic commented Jul 18, 2022

Thanks!

@ydah ydah deleted the add_new_rails_freeze_time branch July 18, 2022 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants