ankane / pretender

Log in as another user in Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

current_user does not change after signing out user, signing in different user

mkilling opened this issue · comments

I‘m using pretender 0.3.1, rails 5.1.3 and devise 4.3.0. In one before_action I log out the current user and log in a different user. I am not impersonating anyone.

Unfortunately, current_user does not change, even though true_user does:

before_user = current_user
sign_out(current_user)
# at this point I expect current_user to be nil, but it is still `before_user`
sign_in(another_user)
# at this point I expect current_user to be `another_user`, but it is still `before_user`

From a quick glance at the code I think that pretender caches current_user in an instance variable, causing this unexpected behaviour.

Hey @mkilling, thanks for the detailed report. This should be fixed on master.