Rails 3 和 Factory Girl 仅在传入属性时创建用户
我正在使用 Rails 3 rc、Factory Girl、Rspec 和 Authlogic。 有什么方法或原因会发生这种情况:
当我创建这样的用户时:
@user = Factory(:user)
我遇到密码确认“太短”的问题。
我的 Factory.rb 是
Factory.define :user do |u|
u.username "Test User"
u.email "[email protected]"
u.password "aoeuaoeu"
u.password_confirmation "aoeuaoeu"
#u.password_confirmation {|u| u.password}
end
但是当我手动传入 :password 和 :password_confirmation 来创建一个工厂时, 它工作得很好。
@user = Factory(:user, :password => "aoeuaoeu",
:password_confirmation => "aoeuaoeu")
有谁知道这可能是什么原因造成的?
I'm using Rails 3 rc, Factory Girl, and Rspec, and Authlogic.
Is there any way or reason why this would happen:
When I create a user like this:
@user = Factory(:user)
I get an issue with password confirmation being "too short".
my factories.rb is
Factory.define :user do |u|
u.username "Test User"
u.email "[email protected]"
u.password "aoeuaoeu"
u.password_confirmation "aoeuaoeu"
#u.password_confirmation {|u| u.password}
end
But when I create one as I pass in :password and :password_confirmation manually,
it works just fine.
@user = Factory(:user, :password => "aoeuaoeu",
:password_confirmation => "aoeuaoeu")
Does anyone have any idea what could be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎与这里的人遇到的问题类似:
Authlogic 和密码和密码确认属性 - 无法访问?
密码和确认必须在属性哈希中传递,如下所示:
有关详细信息,请参阅:
http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
This seems similar to the problem the person here had:
Authlogic and password and password confirmation attributes - inaccessible?
The password and confirmation must be passed in the attributes hash like so:
For more info see:
http://railstutorial.org/chapters/modeling-and-viewing-users-two#top