I'm using devise to handle the authentication process. I am now developing integration tests for my application, starting with the sign in process.
RSpec.describe 'sign in', type: :feature, js: true do
let!(:user) { create(:user)}
scenario 'sign in with correct credentials' do
visit new_user_session_path
fill_in 'Login', with: 'email@email.com'
fill_in 'Password', with: 'password'
click_on 'Sign in'
expect(current_path).to eq(signed_in_path)
end
end
After the test above clicks on the "Sign in" button, a session is created as intended and then the user is redirected to the signed_in_path
. After this redirection, the controller for this path is called and it has a before_action :authenticate_user
.
The problem is, after the redirect, this authenticate_user
method doesn't recognize the current_user
anymore which makes it redirect back to the sign in page and causes the test to fail.
What is causing this loss of session? How can I fix it?
PS: I've included config.include Devise::Test::IntegrationHelpers, type: :feature
to my rails_helper.rb
and the sign_in
helper works great, but I shouldn't use this to test if the sign is page is working correctly.