I want to be able test that after logout the session is invalid. For this I want to check that after login, session exists and i want to get the session details. After logout the session no longer exists.
One way i can think of is to check that session exists in redis after login and doesn't exist in redis after logout. But I'm not sure how to do this.
Please do let me know if there is any other approach that I can try.
Here is what I have so far:
scenario "session is invalidated on logout", js:true do
login_page.login('[email protected]', 'usfyguysgugy')
@user = User.find_by(email: '[email protected]')
page.get_rack_session
end
But this gives error:
Failure/Error: page.get_rack_session
Capybara::ElementNotFound:
Unable to find visible xpath "//body/pre"
I have also tried using redis.keys('*'), but wasn't successful.
Any lead on how to access the session would be helpful.
You're writing feature specs, you shouldn't be accessing the DB/redis/etc directly in those type of tests. Feature tests are all about testing what a user can and cannot do, so to verify that logout ends the session, verify that the logout link no longer exists, and a login link now exists. Something like
If you truly want to verify the details of a session stored in redis, that would be done in a controller or request spec.