Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #769] Fix a false positive for Rails/FreezeTime #770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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