Skip to content

Commit 0be0e41

Browse files
authored
Merge pull request #1008 from samrjenkins/fix-uniqueness-validation-without-index-explicit-disable
Fix `Rails/UniquenessValidationWithoutIndex` false positive on explicit disable
2 parents 1923aea + bafe572 commit 0be0e41

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1008](https://github.com/rubocop/rubocop-rails/pull/1008): Fix `UniqueValidationWithoutIndex` to not detect offenses when a validation specifies `uniqueness: false`. ([@samrjenkins][])

lib/rubocop/cop/rails/unique_validation_without_index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class UniqueValidationWithoutIndex < Base
3131
RESTRICT_ON_SEND = %i[validates].freeze
3232

3333
def on_send(node)
34-
return unless uniqueness_part(node)
34+
return if uniqueness_part(node).falsey_literal?
3535
return if condition_part?(node)
3636
return unless schema
3737

spec/rubocop/cop/rails/unique_validation_without_index_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class User
3232
end
3333
RUBY
3434
end
35+
36+
it 'does not register an offense' do
37+
expect_no_offenses(<<~RUBY)
38+
class User
39+
validates :account, uniqueness: false
40+
end
41+
RUBY
42+
end
3543
end
3644

3745
context 'when the table has an index but it is not unique' do

0 commit comments

Comments
 (0)