Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
numericality: lazily assign submatchers/qualifiers
The numericality matcher has two kinds of qualifiers: those that add new tests directly to the matcher, and those that change the behavior of those tests. For instance, consider `odd` and `strict`. Using `odd` instructs the matcher to verify not only that the attribute can only be set to a number, but that it must be set to an *odd* number. `strict` then instructs the `odd` matcher to make this verification with the assumption that a validation exception will be raised instead of the record producing a validation error. It follows, then, that these qualifiers are order-dependent. This test: should validate_numericality_of(:attr).strict.odd is actually a different test than: should validate_numericality_of(:attr).odd.strict Why? Because if `strict` is written before `odd`, then it doesn't have any submatchers to affect. But if it is written after, then it can see that `odd` is present and can apply itself to it. The fact that users have to remember to specify submatchers in a certain order is inconvenient, and we don't like it. So to fix this, this commit records whenever `strict` or other like qualifiers are used, but then waits to apply them to the other submatchers until #matches? is called (that is, when the matcher is run).
- Loading branch information