Ensure uniqueness validation matcher works with STI#1450
Ensure uniqueness validation matcher works with STI#1450StefSchenkelaars wants to merge 1 commit intothoughtbot:masterfrom
Conversation
| gem "spring-watcher-listen", "~> 2.0.0" | ||
| gem "pg", "~> 0.18" | ||
| gem "sqlite3", "~> 1.3.6" | ||
| gem "aasm" |
There was a problem hiding this comment.
Not sure what the policy is about these kind of tests that require external libraries. I now only require this gem in the relevant spec but it's still needed in the gemfiles. I'm happy to change / remove it.
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 thoughtbot#1245 A similar thing happens when the original class is using an AASM state machine. The state machine settings are stored in a global registry. So when the fake class is initialized, AASM cannot find the settings of the set state machines (due to duplication) in the registry. See thoughtbot#854 These problems are fixed by making the fake class inherrit from the original class. Therefore it closes thoughtbot#1245 and closes thoughtbot#854
1348cd5 to
de575cf
Compare
|
@StefSchenkelaars thanks for working on this, do you still want to work on that? If so I think we can just remove the part of this PR that introduces I can continue this work and give you credits if you're not interested anymore. |
|
Hi @matsales28 |
|
Closing this PR in favor of #1610 |
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
A similar thing happens when the original class is using an AASM
state machine. The state machine settings are stored in a global
registry. So when the fake class is initialized, AASM cannot find
the settings of the set state machines (due to duplication) in the
registry. See #854
These problems are fixed by making the fake class inherrit from the
original class. Therefore it closes #1245 and closes #854