1
我正在用rails 3.1中的secure_password指令。我正在编写rspec模型测试,但无法弄清楚如何在rails 3.1中调用secure_password提供的身份验证方法。Rails 3.1 secure_password和Rspec
describe "authentication" do
before(:each) do
@user = User.create!(@attr)
end
....
describe "it should check credentials" do
describe "it should return false on an invalid password" do
@user.authenticate("wrongpass").should_be false
end
end
end
有什么想法吗?注意:我在我的用户模型
这里使用has_secure_password是最新的错误我的控制台给我:
/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/whiny_nil .rb:48:in method_missing': undefined method
authenticate'for nil:NilClass(NoMethodError)
嘿詹姆斯,谢谢你的回答!不幸的是,它不是。根据github回购,如果验证失败,验证应该返回false,所以false或be_nil都应该工作。我还有一个成功的测试来检查@user是否响应:password_digest。我会继续看,并让你知道。 – sybohy 2011-12-28 06:45:27
请注意,测试“@user respons to:password_digest”测试属性是db架构的一部分,而不是模型中的has_secure_password行。 – 2013-10-14 03:24:09