Closed andyl closed 13 years ago
Can you gist your model and your spec?
Here's the model: https://gist.github.com/967624 Here's the spec: https://gist.github.com/967629
On which attribute are you adding the uniqueness validator?
Also, check out my form of the gist: https://gist.github.com/967720
This is a more concise way of writing the validation specs. You can pass more than one value to the when
method
I'd like to set the uniqueness validation on the ':login' field. In the gist, it's commented out. When I uncomment that validation, I get the error.
Re: multiple tests on a single line - yeah I have used that - in the gist I published I used one line per test so errors would point directly to the failing case.
So this is not an issue with valid_attribute
. the login
attribute is an accessor method on your model. validates_uniqueness_of
tries to query the users table for a login
column but that column doesn't exist. That is what is producing your error.
As for the reason why this was causing all of your specs to fail it is because valid_attribute
called #valid?
on the model as a whole. So it doesn't matter if you're referring to a single attribute or not the entire model is validated. This is probably not ideal, I should switch it to only validate the given attribute.
Actually, I take that back. I'll leave it as is. Otherwise I would be tying the implementation too tightly to ActiveModel.
When I add 'validates_uniqueness_of' to my model, all of my valid_attribute specs fails with error message "undefined method: 'text?' for nil:NilClass".
Is there a workaround ??
Tx, Andy