开发者

Testing user model generated by devise

开发者 https://www.devze.com 2023-02-10 19:40 出处:网络
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 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 !

0

精彩评论

暂无评论...
验证码 换一张
取 消