我正在使用Rails 3 rc,Factory Girl,Rspec和Authlogic。 有没有办法或理由为什么会发生这种情况:
当我创建这样的用户时:
@user = Factory(:user)
我遇到密码确认“太短”的问题。
我的个工厂.rb是
Factory.define :user do |u|
u.username "Test User"
u.email "TestUser@gmail.com"
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")
有没有人知道造成这种情况的原因是什么?
答案 0 :(得分:0)
这似乎与此人的问题类似:
Authlogic and password and password confirmation attributes - inaccessible?
密码和确认必须在属性哈希中传递,如下所示:
before(:each) do
@attr = {
:name => "Example User",
:email => "user@example.com",
:password => "foobar",
:password_confirmation => "foobar"
}
end
有关详细信息,请参阅:
http://railstutorial.org/chapters/modeling-and-viewing-users-two#top