I generated a model using rails generate devise User
, and later added a field to the model using rails generate migration a开发者_如何转开发dd_field_to_user field:string
.
I want to be able to unit test the validation on this field, but no matter what, the users I create are always invalid. I added the attribute to attr_accessible
in the model and all.
Is there something I'm missing?
Thanks in advance!
First find out why your users are invalid. Try creating the user in rails console with something like this
test_user = User.new(:email => "me@email.com", :password => "somesecret")
test_user.save!
The call on test_user.save!
will tell you which validation is failing. It's important to include the !
精彩评论