Skip to content

Ensure uniqueness validation matcher works with STI#1610

Merged
matsales28 merged 1 commit intomainfrom
ensure-uniqueness-works-with-sti
Feb 9, 2024
Merged

Ensure uniqueness validation matcher works with STI#1610
matsales28 merged 1 commit intomainfrom
ensure-uniqueness-works-with-sti

Conversation

@matsales28
Copy link
Copy Markdown
Member

Quotin @StefSchenkelaars on #1450:

The uniqueness validation matcher generates a fake class when the scope name ends on _type. This fake class is a duplicate of the original class. In most cases this is not a problem, however when using single table inheritance (STI), this new fake class is not a subclass of the original class and therefore ActiveRecord will throw an error. See #1245

These problems are fixed by making the fake class inherrit from the original class. Therefore it closes #1245 and closes #854

The uniqueness validation matcher generates a fake class when the
scope name ends on _type. This fake class is a duplicate of the
original class. In most cases this is not a problem, however when
using single table inheritance (STI), this new fake class is not
a subclass of the original class and therefore ActiveRecord will
throw an error. See #1245

These problems are fixed by making the fake class inherrit from the
original class. Therefore it closes #1245 and closes #854
Copy link
Copy Markdown
Collaborator

@vsppedro vsppedro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one thing: any idea why the CI skipped the test/build process for version 3.3.0, using Rails 7.1 with SQLite3?

@matsales28
Copy link
Copy Markdown
Member Author

LGTM! Just one thing: any idea why the CI skipped the test/build process for version 3.3.0, using Rails 7.1 with SQLite3?

Interesting, I didn't notice that. I'm re-running this test process. Not sure why it was skipped

@matsales28 matsales28 merged commit 5781741 into main Feb 9, 2024
@matsales28 matsales28 deleted the ensure-uniqueness-works-with-sti branch February 9, 2024 17:51
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 this pull request may close these issues.

Issue with validates uniqueness and STI/polymorphic models on rails 6? Issue with Shoulda::Matchers::ActiveRecord::Uniqueness::TestModels

3 participants