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

[Fix #762] Fix an error for Rails/FreezeTime #765

Merged
merged 1 commit into from Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_rails_freeze_time.md
@@ -0,0 +1 @@
* [#762](https://github.com/rubocop/rubocop-rails/issues/762): Fix an error for `Rails/FreezeTime` when using `travel_to` with an argument of `current` method without receiver. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/rails/freeze_time.rb
Expand Up @@ -44,6 +44,7 @@ class FreezeTime < Base

def on_send(node)
child_node, method_name = *node.first_argument.children
return unless child_node
return unless current_time?(child_node, method_name) || current_time_with_convert?(child_node, method_name)

add_offense(node) { |corrector| corrector.replace(node, 'freeze_time') }
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/freeze_time_spec.rb
Expand Up @@ -70,4 +70,10 @@
travel_to(Time.zone.yesterday.in_time_zone)
RUBY
end

it 'does not register an offense when using `travel_to` with an argument of `current` method without receiver' do
expect_no_offenses(<<~RUBY)
travel_to(current)
RUBY
end
end