Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails/UniqueValidationWithoutIndex String/Symbol discrepancy #225

Closed
baarkerlounger opened this issue Mar 31, 2020 · 2 comments
Closed

Rails/UniqueValidationWithoutIndex String/Symbol discrepancy #225

baarkerlounger opened this issue Mar 31, 2020 · 2 comments

Comments

@baarkerlounger
Copy link

baarkerlounger commented Mar 31, 2020

Given a model:

class Account < ApplicationRecord
  validates "some_field", uniqueness: true
end

and a schema.rb:

  enable_extension "plpgsql"

  create_table "accounts", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "some_field"
    t.index ["some_field"], name: "some_field_index", unique: true
  end

Rubocop passes.

But changing the model validation to use a symbol rather than a string:

validates :some_field, uniqueness: true

It fails with:

C: Rails/UniqueValidationWithoutIndex: Uniqueness validation should be with a unique index

I would expect both of those to produce the same result.

RuboCop version

0.80.1 (using Parser 2.7.0.5, running on ruby 2.7.0 x86_64-darwin19)

Rails version

6.0.2.2

Ruby version

2.7.0 This appears to work as expected on Ruby 2.7.1

@koic
Copy link
Member

koic commented Apr 2, 2020

I cannot reproduce this issue.
RuboCop Rails 2.5.1 has been released. Will updating to RuboCop 2.5.1 reproduce the issue?
https://github.com/rubocop-hq/rubocop-rails/releases/tag/v2.5.1

@baarkerlounger
Copy link
Author

Turns out the issue actually has nothing to do with Symbols/Strings it's just changing the file at all that does it.

This is actually a duplicate of #227 so will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants