问题描述
Devise gem通过提供after_resetting_password_path_for(resource)
方法,提供了一种自定义成功更新用户密码后发生的情况的方法。在devise宝石(https://github.com/heartcombo/devise/blob/bafc23eae58fd530f4e149a9b17542c577cf7bb3/app/controllers/devise/passwords_controller.rb#L47)的更新操作中调用它。
我在我的{@ {1}}继承的PasswordsController中添加了此方法:
Devise::PasswordsController
根据需要选择此方法。密码更新后,我的class PasswordsController < Devise::PasswordsController
private
def after_resetting_password_path_for(resource)
if params[:initial]
other_path
else
root_path
end
end
end
方法被点击了。
我正在尝试添加测试以测试此附加功能,并且似乎无法正确调用将触发after_resetting_password_path_for(resource)
的更新操作。
在我的after_resetting_password_path_for(resource)
中,我包括:
test_helper.rb
我的测试看起来像(我从另一个SO复制了该测试,并对其进行了稍微Rails 4 + Devise: How to write a test for Devise Reset Password without RSpec?的修改):
class Actiondispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
end
我注释了require 'test_helper'
class ResetPasswordTest < Actiondispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup do
# request.env["devise.mapping"] = Devise.mappings[:user]
@user = users(:logistics)
@reset_password_token = @user.send_reset_password_instructions
end
test "reset user's password" do
# @user.reset_password_token returns "de0e10758c965e84c3d408c9c0be6d6622b13c8be1fd0e98bb7869dc8fce92f6" here
old_password = @user.encrypted_password
# this fails:
assert_difference('ActionMailer::Base.deliveries.count',1) do
post user_password_path,params: { user: {email: @user.email} }
end
patch "/users/password",params: { user: {
reset_password_token: @user.reset_password_token,password: "new-password",password_confirmation: "new-password",} }
# ^ this call returns a 204 but does not actually update the password and does not end up hitting my after_resetting_password_path_for method
# These assertions don't work
assert_not_equal(@user.encrypted_password,old_password)
assert_redirected_to root_path
end
end
这行,因为Devise自述文件说# request.env["devise.mapping"] = Devise.mappings[:user]
rails版本的Rails 5.2.4.3
设计gem版本4.7.1
非常感谢您提供密码更新后测试Unlike controller tests,integration tests do not need to supply the devise.mapping env value,as the mapping can be inferred by the routes that are executed in your tests.
内胆的任何帮助!谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)