我正在运行 Rails 3.2.1 和 rails-rspec 2.8.1 ....当我运行重置用户密码的测试时,似乎重新加载用户对象不会加载新的密码属性....
这是我的测试代码:
describe "Reset password page" do
let(:teacher) { FactoryGirl.create(:teacher, :email=>"jane@gmail.com")}
let(:old_password) { teacher.password }
before do
visit reset_password_form_path
fill_in "Email", with: teacher.email
click_button "Reset Password"
end
it { should have_content('Your new password has been emailed to the address you provided.')}
specify { Teacher.find_by_email("jane@gmail.com").password.should_not == old_password }
## specify { teacher.reload.password.should_not == old_password } ##THIS FAILS
end
指定 {teacher.reload.password.should_not == old_password }失败但指定 { Teacher.find_by_email("jane@gmail.com").password.should_not == old_password } PASSES
所以这告诉我密码被正确保存,但没有被重新加载......有什么想法吗?我正在使用 Rails 3.2.x “has_secure_password” 方法来滚动登录/密码功能。这意味着密码摘要是保存到数据库的内容,密码是虚拟属性(我认为)。