使用 rails 4 我在我的用户模型中使用has_secure_password,trick 说如果我不设置 :password_confirmation 它永远不会被触发但是为什么当我运行测试时我得到错误:密码确认不能为空,如下所示:
Failures:
1) User
Failure/Error: it { should be_valid }
expected #<User id: nil, name: "joe", email: "joe@mail.com", created_at: nil,
updated_at: nil, password_digest: "$2a$04$mcRr/msgYQR3kBVc3kv/m.UotBJuJuSXZKMw
/eHTvU87..."> to be valid, but got errors: Password confirmation can't be blank
我的测试文件看起来像:
require 'spec_helper'
describe User do
before { @user = User.new(name: 'joe', email: 'joe@mail.com', password: 'foo') }
subject { @user }
#....
#....
describe "when password is not present" do
before { @user.password = "" }
it { should_not be_valid }
end
end
为什么我收到此错误,有解决方案吗?谢谢