1# frozen_string_literal: true 2 3module ControllerHelpers 4 # It seems Devise::Test::ControllerHelpers#sign_in doesn't clear out the @current_user 5 # variable of the controller, hence it's not overwritten on retries. 6 # This should be fixed in Devise: 7 # - https://github.com/heartcombo/devise/issues/5190 8 # - https://github.com/heartcombo/devise/pull/5191 9 def sign_in(resource, deprecated = nil, scope: nil) 10 super 11 12 scope ||= Devise::Mapping.find_scope!(resource) 13 14 @controller.instance_variable_set(:"@current_#{scope}", nil) 15 end 16end 17 18Devise::Test::ControllerHelpers.prepend(ControllerHelpers) 19