Closed
Description
Rails 5 added support for expression indexes as follows:
def change
add_index :emails,
'lower(address)',
name: "index_emails_on_address_unique",
unique: true
end
However, it does not seem to be recognised by Rails/UniqueValidationWithoutIndex
rule. I have added a test case below that fails, but should pass instead.
Expected behavior
No offense triggered.
Actual behavior
Offense is being triggered with Uniqueness validation should be with a unique index
message.
Steps to reproduce the problem
Here is the test case we can put into spec/rubocop/cop/rails/unique_validation_without_index_spec.rb
:
context 'with expression indexes' do
let(:schema) { <<~RUBY }
ActiveRecord::Schema.define(version: 2020_02_02_075409) do
create_table "emails", force: :cascade do |t|
t.string "address", null: false
t.index "lower(address)", name: "index_emails_on_LOWER_address", unique: true
end
end
RUBY
it 'registers no offense' do
expect_no_offenses(<<~RUBY)
class Email
validates :address, presence: true, uniqueness: { case_sensitive: false }, email: true
end
RUBY
end
end
RuboCop version
$ [bundle exec] rubocop -V
0.80.1 (using Parser 2.7.0.5, running on ruby 2.6.5 x86_64-darwin18)
Activity