|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe RuboCop::Cop::Rails::DuplicateScope, :config do |
4 | | - it 'registers an offense when a duplicate scope is detected' do |
| 4 | + it 'registers an offense when a duplicate scope with the same `where` clauses is detected' do |
5 | 5 | expect_offense(<<~RUBY) |
6 | 6 | class Post < ApplicationRecord |
7 | 7 | scope :visible, -> { where(visible: true) } |
8 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Multiple scopes share this same where clause. |
| 8 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Multiple scopes share this same expression. |
9 | 9 | scope :hidden, -> { where(visible: true) } |
10 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Multiple scopes share this same where clause. |
| 10 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Multiple scopes share this same expression. |
11 | 11 | scope :new, -> { where(created_at: 1.week.ago..Date.current) } |
12 | 12 | scope :popular, -> { where(comments_count: 1000..Float::INFINITY) } |
13 | 13 | end |
14 | 14 | RUBY |
15 | 15 | end |
16 | 16 |
|
| 17 | + it 'registers an offense when a duplicate scope with the same expression is detected' do |
| 18 | + expect_offense(<<~RUBY) |
| 19 | + class Post < ApplicationRecord |
| 20 | + scope :with_visibility, ->(value) { where(visible: value) } |
| 21 | +
|
| 22 | + scope :visible, -> { with_visibility(true) } |
| 23 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Multiple scopes share this same expression. |
| 24 | + scope :hidden, -> { with_visibility(true) } |
| 25 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Multiple scopes share this same expression. |
| 26 | + end |
| 27 | + RUBY |
| 28 | + end |
| 29 | + |
17 | 30 | it 'does not register an offense when there are no duplicates' do |
18 | 31 | expect_no_offenses(<<~RUBY) |
19 | 32 | class Post < ApplicationRecord |
|
0 commit comments