I have all my controllers using the before_filter :login_required authentication. How do I have my tests login? I''ve tried every combination of process :login, blah but can''t get blah right. Do I have to do the login in each test_*, or just in the setup. As an example, I have a customers_controller_test that is supposed to create 10 customers. The test fails because it is being redirected to account/login. Thanks in advance! Regards, JJ
I store the current user_id in the session to show the currently logged in user. To simulate this in a test, just use: @request.session[''user''] = 3 On Thu, 24 Feb 2005 14:01:58 -0500, John Johnson <johnatl-ee4meeAH724@public.gmane.org> wrote:> I have all my controllers using the before_filter :login_required > authentication. > How do I have my tests login? I''ve tried every combination of process > :login, blah > but can''t get blah right. Do I have to do the login in each test_*, or > just in the > setup. > > As an example, I have a customers_controller_test that is supposed to > create 10 customers. The test fails because it is being redirected to > account/login. > > Thanks in advance! > > Regards, > JJ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- rick http://techno-weenie.net
Supposably there are better solutions, but I did it by bypassing the login procedure: @request.session["user"] = User.authenticate("user", "user_pass") # or simply @request.session["user"] = User.find_by_login "user" Writes the user directly into the session, like a login-controller does it. So the user is logged in and the tests can proceed...
On 24-Feb-2005, at 14:27, Rick Olson wrote:> I store the current user_id in the session to show the currently > logged in user. To simulate this in a test, just use: > > @request.session[''user''] = 3 > > On Thu, 24 Feb 2005 14:01:58 -0500, John Johnson <johnatl-ee4meeAH724@public.gmane.org> > wrote: >> How do I have my tests login? I''ve tried every combination of process >> :login, blah >>Thanks Rick & Michael! Green bars! I don''t think I could have made it difficult enough to work :-) Regards, JJ