设计重置密码集成测试失败

时间:2014-08-24 21:48:04

标签: ruby-on-rails-4 devise integration-testing

您好我为Devise重置密码恢复编写了一个集成测试。我有一个reset_password_token的问题,它始终无效,但应该没问题,因为带有此令牌的用户确实存在。

任何建议表示赞赏。感谢。

这是我的测试:

should "reset his password" do 
  visit "/"
  click_link "Login"

  assert page.has_content?("Log in")

  click_link "Forgot your password?"

  assert page.has_content?("Forgot your password?")
  fill_in 'user[email]', with: @user.email

  assert_difference "ActionMailer::Base.deliveries.size", 1 do
    click_button "Send me reset password instructions"
    assert @user.reload.reset_password_token.present?
  end
  assert page.has_content?("You will receive an email with instructions on how to reset your password in a few minutes.")

  visit edit_user_password_path(reset_password_token: @user.reset_password_token)
  fill_in 'user[password]', with: 'newpassword'
  fill_in 'user[password_confirmation]', with: 'newpassword'
  click_button "Change my password"

  assert page.has_content?("Your password has been changed successfully. You are now signed in.")
end
end

这是邮件视图:

%p
Hello #{@resource.email}!
%p Someone has requested a link to change your password. You can do this through the link   
below.
%p= link_to 'Change my password', edit_password_url(@resource, reset_password_token:   
@token)
%p If you didn't request this, please ignore this email.
%p Your password won't change until you access the link above and create a new one.

2 个答案:

答案 0 :(得分:0)

在您的邮件视图中,更改:

edit_password_url(@resource, reset_password_token:   
@token)

致:

edit_password_url(@resource, :reset_password_token => @resource.password_reset_token)

答案 1 :(得分:0)

本文档可以为您提供帮助:

http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable

查看方法:send_reset_password_instructions它调用set_reset_password_token,它应该在@user实例中可用。