Skip to content

Commit

Permalink
[Fix rubocop#769] Fix a false positive for Rails/FreezeTime
Browse files Browse the repository at this point in the history
Fixes rubocop#769.

This PR fixes a false positive for `Rails/FreezeTime` when using
`travel_to` with an argument of `DateTime.new` with arguments.
  • Loading branch information
koic committed Sep 12, 2022
1 parent 783e2ed commit 614558b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_a_false_positive_for_rails_freeze_time.md
@@ -0,0 +1 @@
* [#769](https://github.com/rubocop/rubocop-rails/issues/769): Fix a false positive for `Rails/FreezeTime` when using `travel_to` with an argument of `DateTime.new` with arguments. ([@koic][])
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rails/freeze_time.rb
Expand Up @@ -43,8 +43,8 @@ class FreezeTime < Base
PATTERN

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

add_offense(node) do |corrector|
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/freeze_time_spec.rb
Expand Up @@ -91,4 +91,10 @@
travel_to(current)
RUBY
end

it 'does not register an offense when using `travel_to` with an argument of `DateTime.new` with arguments' do
expect_no_offenses(<<~RUBY)
travel_to(DateTime.new(2022, 5, 3, 12, 0, 0))
RUBY
end
end

0 comments on commit 614558b

Please sign in to comment.