【发布时间】: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