I recently upgraded my application to rails 7 and now a bunch of my tests are failing with the below error.
ActionDispatch::Request::Session::DisabledSessionError: Your application has sessions disabled. To write to the session you must first configure a session store
I am suspecting this has something to do with devise.
Below is the code that is causing issues.
def login_user(user)
post "/api/v2/login", :params => { :username => user.username, :password => user.password }
assert_response :success, response.body
json = JSON.parse(response.body)
{:authentication_token => json["user"]["authentication_token"]}
end
If I remove the line config.api_only = true from the application.rb file then the test cases pass without any hitch but I can't really remove that line due to other issues. Does anybody a proper solution for this issue ?
I found a similar question: Rails 7 API only app requiring session store with Devise
where it's suggested to add following to your config/application.rb :
config.session_store :cookie_store, key: '_interslice_session'
config.middleware.use ActionDispatch::Cookies
config.middleware.use config.session_store, config.session_options
based on this issue on github
Adding code below to config/initializers/devise.rb works for me.
config.warden do |manager|
manager.scope_defaults :user, store: false
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With