I added an option that checks whether the validation of uniqueness is skipped, when the attribute in question has a value of nil. So basically it tries to enforce something along the lines of
validates_uniqueness_of :attr, :allow_nil => true # (a)
The branch can be found here: http://github.com/JulianKniephoff/shoulda/tree/validate_uniqueness_of_allow_nil
validate_uniqueness_of with allow_nil option given now matches models having such a clause in them. It does not match a model with just
validates_uniqueness_of :attr # (b)
as it does not allow nil duplicates. A class with statement (a) on the other hand is no longer matched by just validate_uniqueness_of (without allow_nil option) as it allows a duplicate: nil. Accordingly, validates_uniqueness_of without allow_nil does (still) match a model with (b) in it.
validates_uniqueness_of :attr, :allow_nil => true
I hope this behavior conforms with Shoulda.
any chance to have this merged in - if not, any reason why?
I'd like to see this get merged in as well.
+1 for merging this in
This looks useful - can you file a pull request over at shoulda-matchers? That's where all of the "real code" lives now. Shoulda has become just a meta-gem that depends on that code.
I'm gonna look into that as soon as possible.
any update on this? would be a cool feature!