导轨夹具和功能测试
我有一个基于从头开始的railscasts身份验证的用户脚手架,它使用密码属性,我如何允许测试通过并使我的装置的密码不是表中的字段,而password_hash和password_salt是? 我在模型中有以下代码,我认为这是导致用户不增加的第一行。我该如何解决这个问题?
validates_presence_of :password, :on => :create
validates_confirmation_of :password
我想我发现了这个问题,但不知道如何解决它。我调用以下代码,它不包含密码或密码确认,即使我尝试将其添加到属性中。
post :create, user: @user.attributes
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.attributes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在控制器中设置密码,如下所示:
如果您仍想这样做:
将此行添加到用户模型中:
请注意,attr_accessible 可能会导致安全漏洞。了解有关 attr_accessible 和 attr_accessible 的更多信息在使用它们之前先进行 attr_protected。
Set the password in the controller like this:
If you still want to do like this:
add this line to the user model:
Note that attr_accessible might lead to a security hole. Learn more about attr_accessible & attr_protected before using them.