Skip to content

Commit

Permalink
[Fix rubocop#762] Fix an error for Rails/FreezeTime
Browse files Browse the repository at this point in the history
Fixes rubocop#762.

This PR fixes an error for `Rails/FreezeTime` when using `travel_to` with
an argument of `current` method without receiver.
  • Loading branch information
koic committed Sep 9, 2022
1 parent 2f68e9f commit b56f67d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
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

0 comments on commit b56f67d

Please sign in to comment.