I'm writing integration tests for a "who's logged in" function for a
project I'm working on. The system checks the database to see when
the last request was made, and to ensure that it only returns user
objects (from the user's table) where last_request was <= 5 minutes
ago AND the user is not logged out. It keeps track of this by, when
users manually log out, timestamping a "last_logout" column in the DB.
Well here's the problem: when testing the logout functionality, my
test isn't keeping track of a session variable called :user. The
logout action uses that to track which user to log out.
So the tests fail because I'm checking the number of users returned by
my whos_logged_in method (described above) because upon logout, it
can't write to the database because the session[:user] variable isn't
I've tried manually specifying a variable inside an open_session
block, but that doesn't seem to work (method undefined errors); I'm at
a loss here, and I haven't seen anything helpful in the
documentation. Any ideas how I can manually set a session variable
inside an integration test?