# Functional testing with filters

**URL:** <https://www.ruby-forum.com/t/functional-testing-with-filters/152626>\
**Category:** Rails\
**Created:** [November 5, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/functional-testing-with-filters/152626 "2008-11-05T20:17:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/functional-testing-with-filters/152626/1 "2008-11-05T20:17:52Z")

</div>

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:

`post :login, :user => {login params}
follow_redirect
assertions`

If I can’t use “follow\_redirect”, how do I set up my tests so the  
controller treats the test methods as logged in?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/functional-testing-with-filters/152626/2 "2008-11-05T20:43:42Z")

</div>

On Nov 5, 7:04 pm, Ed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> assertions
> 
> 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/functional-testing-with-filters/152626/3 "2008-11-05T21:00:50Z")

</div>

But of course. Thanks!

On Nov 5, 2:43 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
