Wes Gamble
2008-Oct-02 15:18 UTC
Simple testing question: Handling login in functional tests
When writing functional (e.g. controller unit) tests, I''m running into a simple problem that I''m sure is very easy to fix, but I''m not sure of the correct approach. If I request a resource in my test case, via something like "get :get_template" (where :get_template is an action on my controller), I get a 302 and when I inspect the response, I see that it is redirecting me to the login page (which makes sense since the :get_template action is protected by authentication). How do I handle the login requirement in my functional test? I use acts_as_authenticated, which mandates an AccountController to manage login, so by definition, I need to do something (meet the login requirements) in another controller (Account) than the one I am testing. Does that imply that I''m immediately in integration test territory? Is there a simple way to manage it in the functional test? I considered monkey patching the controller to skip the check_authorization before_filter so that the test requests won''t be redirected, but that seems like it''s overkill. Thanks, Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robby Russell
2008-Oct-02 15:32 UTC
Re: Simple testing question: Handling login in functional tests
Generally, you''ll need to mock out your login checks in your setup/before. On Thu, Oct 2, 2008 at 8:18 AM, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > When writing functional (e.g. controller unit) tests, I''m running into a > simple problem that I''m sure is very easy to fix, but I''m not sure of > the correct approach. > > If I request a resource in my test case, via something like "get > :get_template" (where :get_template is an action on my controller), I > get a 302 and when I inspect the response, I see that it is redirecting > me to the login page (which makes sense since the :get_template action > is protected by authentication). > > How do I handle the login requirement in my functional test? I use > acts_as_authenticated, which mandates an AccountController to manage > login, so by definition, I need to do something (meet the login > requirements) in another controller (Account) than the one I am testing. > Does that imply that I''m immediately in integration test territory? > > Is there a simple way to manage it in the functional test? I considered > monkey patching the controller to skip the check_authorization > before_filter so that the test requests won''t be redirected, but that > seems like it''s overkill. > > Thanks, > Wes > -- > Posted via http://www.ruby-forum.com/. > > > >-- Robby Russell Chief Evangelist, Partner PLANET ARGON, LLC design // development // hosting http://www.planetargon.com/ http://www.robbyonrails.com/ aim: planetargon +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4068 [fax] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joshua Abbott
2008-Oct-02 15:40 UTC
Re: Simple testing question: Handling login in functional te
Just saw at Neeraj''s site this morning: http://www.neeraj.name/blog/articles/739-testing-tip-use-method-login_as -- Josh http://www.iammrjoshua.com Robby Russell wrote:> Generally, you''ll need to mock out your login checks in your > setup/before. > > On Thu, Oct 2, 2008 at 8:18 AM, Wes Gamble > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> Thanks, >> Wes >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > > -- > Robby Russell > Chief Evangelist, Partner > > PLANET ARGON, LLC > design // development // hosting > > http://www.planetargon.com/ > http://www.robbyonrails.com/ > aim: planetargon > > +1 503 445 2457 > +1 877 55 ARGON [toll free] > +1 815 642 4068 [fax]-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joshua Abbott
2008-Oct-02 15:40 UTC
Re: Simple testing question: Handling login in functional te
Just saw this at Neeraj''s site this morning: http://www.neeraj.name/blog/articles/739-testing-tip-use-method-login_as -- Josh http://www.iammrjoshua.com Robby Russell wrote:> Generally, you''ll need to mock out your login checks in your > setup/before. > > On Thu, Oct 2, 2008 at 8:18 AM, Wes Gamble > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> Thanks, >> Wes >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > > -- > Robby Russell > Chief Evangelist, Partner > > PLANET ARGON, LLC > design // development // hosting > > http://www.planetargon.com/ > http://www.robbyonrails.com/ > aim: planetargon > > +1 503 445 2457 > +1 877 55 ARGON [toll free] > +1 815 642 4068 [fax]-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2008-Oct-02 16:19 UTC
Re: Simple testing question: Handling login in functional te
I also found this approach which is interesting because it actually forces a test of the login process each time. http://alexbrie.net/1526/functional-tests-with-login-in-rails/ Thanks for the responses. Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---