heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
23.98k stars 5.55k forks source link

The `:"@current_#{scope}"` controller variable should be reset in `Devise::Test::ControllerHelpers#sign_in` #5190

Open rymai opened 4 years ago

rymai commented 4 years ago

Environment

Current behavior

When using rspec-retry, the currently logged-in user isn't totally reset, i.e. @controller.instance_variable_get(:"@current_#{scope}") still returns the user logged-in in the first try. This can lead to failures/false positive, e.g. https://gitlab.com/gitlab-org/gitlab/issues/202072.

Expected behavior

Current user should be cleared when logging-in a new user, upon example retry.

I have applied the following patch locally:

module ControllerHelpers
  def sign_in(resource, deprecated = nil, scope: nil)
    super

    scope ||= Devise::Mapping.find_scope!(resource)

    @controller.instance_variable_set(:"@current_#{scope}", nil)
  end
end

Devise::Test::ControllerHelpers.prepend(ControllerHelpers)
rymai commented 4 years ago

I've opened https://github.com/heartcombo/devise/pull/5191 to fix that.