Forum: Ruby on Rails functional testing with filters

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ed (Guest)
on 2008-11-05 21:17
(Received via mailing list)
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?
Frederick C. (Guest)
on 2008-11-05 21:43
(Received via mailing list)
On Nov 5, 7:04 pm, Ed <removed_email_address@domain.invalid> wrote:
> 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
Ed (Guest)
on 2008-11-05 22:00
(Received via mailing list)
But of course.  Thanks!


On Nov 5, 2:43 pm, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.