# Trouble with functional tests

**URL:** <https://www.ruby-forum.com/t/trouble-with-functional-tests/84948>\
**Category:** Rails\
**Created:** [February 8, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948 "2007-02-08T20:28:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [February 8, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948/1 "2007-02-08T20:28:44Z")

</div>

I’m having trouble making my functional tests work. I’m trying to  
simulate an action performed while a user is logged in, but it only  
redirects me to the signin page as if no user was logged in.

Here’s my functional test:

def test\_signout\_with\_valid\_user  
get :signout, {}, { :user =\> users(:jeff).id }  
assert\_redirected\_to home\_path  
end

The first user in my users.yml fixtures file is named jeff, with an id  
of 1.

Here’s my admin controller’s signout method:

before\_filter :check\_authentication, :except =\> [:signin, :show,  
:reset\_passwords]

def signout  
session[:user] = nil  
session[:intended\_action] = nil  
redirect\_to home\_path  
end

Here’s my application.rb check\_authentication method:

def check\_authentication  
unless session[:user]  
session[:intended\_action] = params  
redirect\_to signin\_path  
end  
end

When I use the actual application, it works fine–I’m able to sign in,  
sign out, everything works as expected. But when I run the functional  
test, I get:

test\_signout\_with\_valid\_user(AdminControllerTest)  
[test/functional/admin\_control  
ler\_test.rb:42]:  
response is not a redirection to all of the options supplied  
(redirection is \<{"  
action"=\>“signin”, “controller”=\>“admin”}\>), difference:  
\<{“action”=\>“index”, “c  
ontroller”=\>“comics”}\>

What am I doing wrong? As far as I can tell, I’m following exactly how  
it’s described in Agile Web Dev v2, page 194.

Any help would be great. Thanks!

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [February 8, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948/2 "2007-02-08T20:32:00Z")

</div>

Use @request.session instead of parameters to #get.

Jason

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [February 8, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948/3 "2007-02-08T20:35:09Z")

</div>

Jason R. wrote:

> Use @request.session instead of parameters to #get.
> 
> Jason

Thanks, that worked!

Is the Agile Web Dev book outdated already? Sigh.

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [February 28, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948/4 "2007-02-28T16:57:03Z")

</div>

is using @request.session a workaround or is that the new correct  
syntax?

is get :signout, {}, { :user =\> users(:jeff).id } deprecated in  
1.2.2?

i had read that get :signout, {}, { :user =\> users(:jeff).id } not  
working was a bug and will be fixed in 1.2.3, but if i shouldn’t be  
using that syntax anyway because it is deprecated then i will move my  
tests to the new syntax.

thank you, in advance.

On Feb 8, 2:35 pm, Jeff C.man [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 2, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948/5 "2007-03-02T20:11:11Z")

</div>

It’s a bug and will (is?) fixed in Rail 1.2.3

[http://dev.rubyonrails.org/ticket/7372](http://dev.rubyonrails.org/ticket/7372)

Jason

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 2, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/trouble-with-functional-tests/84948/6 "2007-03-02T20:24:17Z")

</div>

Okay, thank you.

On 3/2/07, Jason R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > On Feb 8, 2:35 pm, Jeff C.man \<
> > 
> > > Jeff
> > > 
> > > –  
> > > Posted viahttp://www.ruby-forum.com/.
> > 
> > > >

–  
Thomas M.  
removed\_email\_address@domain.invalid
