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>