I'm using system tests to verify that the following flow works as expected for a user:
- Sign up in a form
- Get signed in
- Visit account page
- Update account information
However, I'm getting an error after user creation:
Puma caught this error: Couldn't find User with 'id'=16 (ActiveRecord::RecordNotFound)
/Me/MyComputer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active_record/core.rb:189:in `find'
/Me/MyComputer/Documents/my_app/app/controllers/application_controller.rb:30:in `current_user'
The error is pointing to the code that sets current_user
in application_controller
:
def current_user
if session[:user_id]
@current_user ||= User.find(session[:user_id])
end
end
Is my assumption correct that it's not possible to access session in tests? And if so - how can I then set current_user
so I can test my scenario above? If not so - what could be causing the error?
Aucun commentaire:
Enregistrer un commentaire