Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

Integration test, login with session is reset between http requests in the same test

$
0
0

I'm upgrading our application from rails 6.2 to 7.0.4 and have encountered an error where the session in the controller is reset after each http request, which did not happen before. This only happens in the test env and not in dev env.

When the user login and we have finished to authentication we set the following:

  def login_user!    session[:user_id] = @user.id    .....  end

When the user tries to visit another link we check the following

 def logged_in?   session[:user_id].present? end

The test:

test 'updates locale' do  post login_path, params: { email: user.email, password: user.password }, as: :json  patch user_path(user), params: { user: { locale: 'en' } }, as: :jsonend

Usually I use the first line login_path to set the session so that I can test other http requests as metnioned here. However it seems like the session is reset after each call in rails 7.When I do the second request I get the following error: <ActionDispatch::Request::Session:0x25648 not yet loaded>


Viewing all articles
Browse latest Browse all 873

Trending Articles