开发者

Rails fixtures and functional tests

I have a user scaffold based off of railscasts authentication from scratch and it uses the password attribute, how would I allow the test to pass and make my fixtures with password not being a field in the table while password_hash and password_salt are? I have in the model the following code, and it is the first line that I believe causes user to not be incremented. How can I fix this?

validates_presence_of :password, :on => :create
validates_confirmation_of :password

I think I found the issue but have no idea how to fix it. I call the following code and it doesn't include password or password_confirmation even though I try to add it to the attributes.

post :create, user: @user.att开发者_开发问答ributes


Set the password in the controller like this:

@user = User.new
@user.name = params[:user][:name]
@user.password = params[:user][:password]

If you still want to do like this:

@user = User.create(params[:user])

add this line to the user model:

attr_accessible :password

Note that attr_accessible might lead to a security hole. Learn more about attr_accessible & attr_protected before using them.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜