Authlogic和密码,确认密码属性 - 无法访问?
-
25-09-2019 - |
题
进出口试图测试我成功地创建的登录(使用authlogic)后的新用户。香港专业教育学院增加了几个新的领域给用户,从而只是想确保让用户正确保存。
问题是,尽管创建一个有效的用户工厂,每当我试图抓住它的属性张贴到创建方法,密码和确认密码被ommitted。我presuem这是一个安全的方法是,在后台执行authlogic。这会导致失败的验证和测试失败。
我想知道我如何克服这个问题?我只能手工键入的属性了,但,这并不显得很干燥。
context "on POST to :create" do
context "on posting a valid user" do
setup do
@user = Factory.build(:user)
post :create, :user => @user.attributes
end
should "be valid" do
assert @user.valid?
end
should_redirect_to("users sentences index page") { sentences_path() }
should "add user to the db" do
assert User.find_by_username(@user.username)
end
end
##User factory
Factory.define :user do |f|
f.username {Factory.next(:username) }
f.email { Factory.next(:email)}
f.password_confirmation "password"
f.password "password"
f.native_language {|nl| nl.association(:language)}
f.second_language {|nl| nl.association(:language)}
end
解决方案
您绝对无法读取来自用户对象的密码和password_confirmation。您需要在:password
和:password_confirmation
到@user.attributes
哈希合并。如果存储了哈希共同的地方与你的工厂的定义其余部分,它不是超级干的,但它是比硬编码到您的测试。
不隶属于 StackOverflow