|
24 | 24 | RUBY
|
25 | 25 | end
|
26 | 26 |
|
| 27 | + it 'registers an offense when using `left_joins(:foo).where(foo: {id: nil})` without receiver' do |
| 28 | + expect_offense(<<~RUBY) |
| 29 | + left_joins(:foo).where(foo: { id: nil }).where(bar: "bar") |
| 30 | + ^^^^^^^^^^^^^^^^ Use `where.missing(:foo)` instead of `left_joins(:foo).where(foo: { id: nil })`. |
| 31 | + RUBY |
| 32 | + |
| 33 | + expect_correction(<<~RUBY) |
| 34 | + where.missing(:foo).where(bar: "bar") |
| 35 | + RUBY |
| 36 | + end |
| 37 | + |
27 | 38 | it 'registers an offense when using `left_outer_joins(:foo).where(foos: {id: nil})`' do
|
28 | 39 | expect_offense(<<~RUBY)
|
29 | 40 | Foo.left_outer_joins(:foo).where(foos: { id: nil }).where(bar: "bar")
|
|
46 | 57 | RUBY
|
47 | 58 | end
|
48 | 59 |
|
| 60 | + it 'registers an offense when using `where(foos: {id: nil}).left_joins(:foo)` without receiver' do |
| 61 | + expect_offense(<<~RUBY) |
| 62 | + where(foos: { id: nil }).left_joins(:foo).where(bar: "bar") |
| 63 | + ^^^^^^^^^^^^^^^^ Use `where.missing(:foo)` instead of `left_joins(:foo).where(foos: { id: nil })`. |
| 64 | + RUBY |
| 65 | + |
| 66 | + expect_correction(<<~RUBY) |
| 67 | + where.missing(:foo).where(bar: "bar") |
| 68 | + RUBY |
| 69 | + end |
| 70 | + |
49 | 71 | it 'registers an offense when using `where(foos: {id: nil}, bar: "bar").left_joins(:foo)`' do
|
50 | 72 | expect_offense(<<~RUBY)
|
51 | 73 | Foo.where(foos: { id: nil }, bar: "bar").left_joins(:foo)
|
|
57 | 79 | RUBY
|
58 | 80 | end
|
59 | 81 |
|
| 82 | + it 'registers an offense when using `where(foos: {id: nil}, bar: "bar").left_joins(:foo)` without receiver' do |
| 83 | + expect_offense(<<~RUBY) |
| 84 | + where(foos: { id: nil }, bar: "bar").left_joins(:foo) |
| 85 | + ^^^^^^^^^^^^^^^^ Use `where.missing(:foo)` instead of `left_joins(:foo).where(foos: { id: nil })`. |
| 86 | + RUBY |
| 87 | + |
| 88 | + expect_correction(<<~RUBY) |
| 89 | + where(bar: "bar").where.missing(:foo) |
| 90 | + RUBY |
| 91 | + end |
| 92 | + |
60 | 93 | it "registers an offense when using `left_joins(:foo).where(foos: {id: nil}, bar: 'bar')`" do
|
61 | 94 | expect_offense(<<~RUBY)
|
62 | 95 | Foo.left_joins(:foo).where(foos: { id: nil }, bar: "bar")
|
|
0 commit comments