From 533b9425db78884813ef3853a89a55b9fa8a0dd3 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Sat, 9 Dec 2023 11:59:53 +0200 Subject: [PATCH] Fix an error for `Rails/WhereMissing` where join method is called without arguments --- ...ror_for_where_missing_where_joins_called_without_args.md | 1 + lib/rubocop/cop/rails/where_missing.rb | 2 +- spec/rubocop/cop/rails/where_missing_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_error_for_where_missing_where_joins_called_without_args.md diff --git a/changelog/fix_error_for_where_missing_where_joins_called_without_args.md b/changelog/fix_error_for_where_missing_where_joins_called_without_args.md new file mode 100644 index 0000000000..c03877f7d8 --- /dev/null +++ b/changelog/fix_error_for_where_missing_where_joins_called_without_args.md @@ -0,0 +1 @@ +* [#1206](https://github.com/rubocop/rubocop-rails/issues/1206): Fix an error for `Rails/WhereMissing` where join method is called without arguments. ([@fatkodima][]) diff --git a/lib/rubocop/cop/rails/where_missing.rb b/lib/rubocop/cop/rails/where_missing.rb index 168d2516d1..915fd53301 100644 --- a/lib/rubocop/cop/rails/where_missing.rb +++ b/lib/rubocop/cop/rails/where_missing.rb @@ -36,7 +36,7 @@ class WhereMissing < Base PATTERN def on_send(node) - return unless node.first_argument.sym_type? + return unless node.first_argument&.sym_type? root_receiver = root_receiver(node) where_node_and_argument(root_receiver) do |where_node, where_argument| diff --git a/spec/rubocop/cop/rails/where_missing_spec.rb b/spec/rubocop/cop/rails/where_missing_spec.rb index fde3476564..532d09104b 100644 --- a/spec/rubocop/cop/rails/where_missing_spec.rb +++ b/spec/rubocop/cop/rails/where_missing_spec.rb @@ -315,6 +315,12 @@ def test Foo.left_joins(bar: :foo).where(bars: { id: nil }) RUBY end + + it 'does not register an offense when using `left_joins` without arguments' do + expect_no_offenses(<<~RUBY) + Foo.left_joins(left_joins).where(bars: { id: nil }) + RUBY + end end context 'Rails 6.0', :rails60 do