Skip to content

Commit 1de4eb3

Browse files
authored
Merge pull request rubocop#810 from koic/fix_error_for_rails_freeze_time
[Fix rubocop#809] Fix an error for `Rails/FreezeTime`
2 parents 0ba3732 + 93f4bb7 commit 1de4eb3

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#809](https://github.com/rubocop/rubocop-rails/issues/809): Fix an error for `Rails/FreezeTime` when using `travel_to` without argument. ([@koic][])

lib/rubocop/cop/rails/freeze_time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FreezeTime < Base
4343
PATTERN
4444

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

spec/rubocop/cop/rails/freeze_time_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,10 @@
9797
travel_to(DateTime.new(2022, 5, 3, 12, 0, 0))
9898
RUBY
9999
end
100+
101+
it 'does not register an offense when using `travel_to` without argument' do
102+
expect_no_offenses(<<~RUBY)
103+
travel_to
104+
RUBY
105+
end
100106
end

0 commit comments

Comments
 (0)