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

Custom case insensitive index fails to validate #1207

Closed
stephendolan opened this issue May 16, 2019 · 1 comment · Fixed by #1211
Closed

Custom case insensitive index fails to validate #1207

stephendolan opened this issue May 16, 2019 · 1 comment · Fixed by #1211
Milestone

Comments

@stephendolan
Copy link

Using Shoulda Matchers 4.0.1 with Rails 6.0.0.rc1.

Rails allows you to create case-insensitive unique indices like this:
add_index :api_tokens, "lower(token)", unique: true

In PostgreSQL, this would generate:
"index_api_tokens_on_lower_token" UNIQUE, btree (lower(token::text))

In my model spec, I've tried validating:
it { should have_db_index(:token).unique }
it { should have_db_index("lower(token::text)").unique }
it { should have_db_index("lower(token)").unique }

I get some variation of the following failure no matter what form the validation takes:
Expected ApiToken to have a unique index on columns lower(token::text) ()

Is there some way to accommodate for this type of index in the existing gem functionality?

@mcmire
Copy link
Collaborator

mcmire commented May 16, 2019

There is not, but this has been reported already: #945. I don't have any bandwidth at the moment unfortunately to implement this but I would gladly take a PR!

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

Successfully merging a pull request may close this issue.

2 participants