On Jan 30, 2006, at 7:22 PM, Michael G. wrote:
I added a small method in test_helper.rb to set the session for me,
passing it the member (user) that is supposed to be logged in.
@request.session[:member_id] = member.id
I then can call set_session_for in my test methods to have them
logged in. Works well for me.
Yes, this is what I do. One line isn’t too much.
naming the helper method log_in(member) and then keep the code that
does sets up the log in (in this case setting a session parameter)
in the log_in helper method. Then you only have to change the guts
of one method if your log in implementation changes.
Yes. By properly abstracting (set_session_for) and properly testing
the login code you will get a clear indication why all your logged-in
tests are failing.
This way if you change the login code all your tests requiring a
valid session will fail but you only have to fix your tests in one
place. (If you’re constantly changing how valid sessions are
represented you’re doing something very wrong.)
You don’t want to test your login code for every logged-in action,
that’s why you wrote a test for your filters. I create a test-only
DummyController for testing login and other filters which gives me a
clear indication what is broken with which filter.
When I’m testing an action that requires the user to be logged in I
want to test the the action, not that the login filter works.
PS: If you can’t figure out what part of your login system is broken
from your tests you obviously don’t have enough tests.
Eric H. - firstname.lastname@example.org - http://segment7.net
This implementation is HODEL-HASH-9600 compliant