Skip to content

Commit 6b5424e

Browse files
authored
Merge pull request rubocop#770 from koic/fix_a_false_positive_for_rails_freeze_time
[Fix rubocop#769] Fix a false positive for `Rails/FreezeTime`
2 parents 32daa2f + 614558b commit 6b5424e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/rails/freeze_time.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class FreezeTime < Base
4343
PATTERN
4444

4545
def on_send(node)
46-
child_node, method_name = *node.first_argument.children
47-
return unless child_node
46+
child_node, method_name, time_argument = *node.first_argument.children
47+
return if time_argument || !child_node
4848
return unless current_time?(child_node, method_name) || current_time_with_convert?(child_node, method_name)
4949

5050
add_offense(node) do |corrector|

spec/rubocop/cop/rails/freeze_time_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,10 @@
9191
travel_to(current)
9292
RUBY
9393
end
94+
95+
it 'does not register an offense when using `travel_to` with an argument of `DateTime.new` with arguments' do
96+
expect_no_offenses(<<~RUBY)
97+
travel_to(DateTime.new(2022, 5, 3, 12, 0, 0))
98+
RUBY
99+
end
94100
end

0 commit comments

Comments
 (0)