【问题标题】:Devise reset password integration test failing设计重置密码集成测试失败
【发布时间】:2014-08-24 21:48:03
【问题描述】:

您好,我为 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.

【问题讨论】:

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


    【解决方案1】:

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

    edit_password_url(@resource, reset_password_token:   
    @token)
    

    收件人:

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

    【讨论】:

    • 不,抱歉。还是一样:/重置密码流程在我手动执行时确实有效,但测试总是失败:/
    【解决方案2】:

    本文档应该对您有所帮助:

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

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

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多