开发者

Rails fixtures and functional tests

开发者 https://www.devze.com 2023-03-15 00:07 出处:网络
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 i

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

精彩评论

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