shoulda-matchers
shoulda-matchers copied to clipboard
Ensure uniqueness validation matcher works with STI
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