简体   繁体   中英

Testing user model generated by devise

I generated a model using rails generate devise User , and later added a field to the model using rails generate migration add_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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM