Skip to content

Commit

Permalink
Merge pull request #770 from koic/fix_a_false_positive_for_rails_free…
Browse files Browse the repository at this point in the history
…ze_time

[Fix #769] Fix a false positive for `Rails/FreezeTime`
  • Loading branch information
koic authored Sep 13, 2022
2 parents 32daa2f + 614558b commit 6b5424e
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 6b5424e

Please sign in to comment.