How do I do functional tests on controller methods protected by before filters, without using the soon-to-be-deprecated "follow_redirect"? Say I have a method called index, filtered by check_login. If the user is not logged in, they get redirected to the login method, which logs them in and directs them to index. In my functional tests, I can hit index like this: <code>post :login, :user => {login params} follow_redirect assertions</code> If I can''t use "follow_redirect", how do I set up my tests so the controller treats the test methods as logged in? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 5, 7:04 pm, Ed <haywood...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How do I do functional tests on controller methods protected by before > filters, without using the soon-to-be-deprecated "follow_redirect"? > > Say I have a method called index, filtered by check_login. If the > user is not logged in, they get redirected to the login method, which > logs them in and directs them to index. In my functional tests, I can > hit index like this: > > <code>post :login, :user => {login params} > follow_redirect > assertions</code> > > If I can''t use "follow_redirect", how do I set up my tests so the > controller treats the test methods as logged in?fake up the session with what would be there if the user were logged in (eg @request.session[:user_id] = users(:bob).id) Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
But of course. Thanks! On Nov 5, 2:43 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 5, 7:04 pm, Ed <haywood...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > How do I do functional tests on controller methods protected by before > > filters, without using the soon-to-be-deprecated "follow_redirect"? > > > Say I have a method called index, filtered by check_login. If the > > user is not logged in, they get redirected to the login method, which > > logs them in and directs them to index. In my functional tests, I can > > hit index like this: > > > <code>post :login, :user => {login params} > > follow_redirect > > assertions</code> > > > If I can''t use "follow_redirect", how do I set up my tests so the > > controller treats the test methods as logged in? > > fake up the session with what would be there if the user were logged > in (eg @request.session[:user_id] = users(:bob).id) > > Fred--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---