I have a test for uniqueness which works:
it { should validate_uniqueness_of(:name).case_insensitive }
however when I try to do a similar test for name it fails
it { should validate_presence_of(:name).allow_blank }
I get this error: undefined method
allow_blank'`
According to this list, there's no method in shoulda that can be chained to validate_presence_of that would support what you want to do. Have a look at the source code of the matcher here.
However, there is another matcher you can use:
it { should allow_value("", nil).for(:name) }
Which tests if blank values can be applied to your attribute.
The full test would then be
it { should validate_presence_of(:name) }
it { should allow_value("", nil).for(:name) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With