# Functional testing woes

**URL:** <https://www.ruby-forum.com/t/functional-testing-woes/79052>\
**Category:** Rails\
**Created:** [December 11, 2006, 9:55pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052 "2006-12-11T21:55:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [December 11, 2006, 9:55pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052/1 "2006-12-11T21:55:50Z")

</div>

hey all,

finished coding unit tests for a rails app and am moving on to the next  
step to try to give the code to test code ratio a bit of a boost. can’t  
figure out how to test some of the stuff the way its implemented and  
also have some general confusion about the more common aspects.

first the more common: in the agile web dev book (1st ed) it shows how  
you can write a login method in the test\_helper.rb and then you can use  
that from therein when testing stuff that requires the user to be  
logged in… ok so this only works for the controller that the login  
method is inside of ?? (not the test helper but the actual login  
mechanism)

writing the functional test for the login controller doesn’t seem too  
bad, but does this mean for every other controller that you need to be  
logged in to use needs to be passed the session variables to make it  
look like the user is logged in? i can’t do something like post  
:controller =\> login, :action =\> login so the helper could be used in  
all functional tests?

next question, my app required some more advanced interface stuff…  
basically there’s tabs with different pages/forms and when switching  
tabs the current state of the form is saved into a serializable session  
object before changing tabs. because of the demanding interface i put  
all that sort of functionality into an ‘interface’ controller… so if i  
want to write a functional test for checking functionality of the  
customer controller code (forms and screens for customer data) i can’t  
call the interface methods. what do i do? test what i can by only  
calling stuff in the controller in question and leave the rest to  
integration tests (that’s what their called right?)

thanks  
stuart  
stuart

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [December 11, 2006, 10:32pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052/2 "2006-12-11T22:32:02Z")

</div>

For testing controllers which require login, there was a thread earlier  
on  
this list, search for the thread “Testing Actions Requiring A Login”.

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [December 12, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052/3 "2006-12-12T16:08:26Z")

</div>

thanks that helped…

one more question:  
if i have an action that redirects to another action and i test this to  
be true with an assert\_redirected\_to shouldn’t the code in the action  
that its being redirected to get run also? because the action that my  
code is redirected to is supposed to create a new user, but when i look  
in the session for the user id its not there and when i look in the  
table its not there either… do i have to do another ‘get’ to have the  
code in the next action run?

thanks  
stuart

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [December 12, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052/4 "2006-12-12T17:44:49Z")

</div>

that’s not what i’m experiencing right now… looked in the logs and i  
see the redirect and the 302, but code in the action doesn’t seem to  
come up in the log. i just did a ‘get’ for the page and things are  
working as they should…

it seems like i go just a little ways before something else pops up…  
i’m passing an active record object in the flash (its unsaved that’s  
why i didn’t pass the id and i put it in the flash instead of params  
because at the time i didn’t know any better)… seems like passing the  
object in the flash preserves the attributes fine, but unlike the  
actual rails app the copy that goes in the flash does not preserve the  
values stored in the object attr\_accessors. any ideas? i guess i could  
switch it over to use params hash instead of flash hash, but shouldn’t  
this work?

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [December 12, 2006, 8:17pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052/5 "2006-12-12T20:17:59Z")

</div>

David

> –  
> Q. What’s a good holiday present for the serious Rails developer?  
> A. RUBY FOR RAILS by David A. Black ([Ruby for Rails](http://www.manning.com/black))  
> aka The Ruby book for Rails developers!  
> Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
> A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

Mr. Black, I love your new sig 😉

This should also be included in the FAQ of the Rails list. Faisal, are  
you  
listening?

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [December 12, 2006, 4:12pm UTC](https://www.ruby-forum.com/t/functional-testing-woes/79052/6 "2006-12-12T16:12:28Z")

</div>

Hi –

On Tue, 12 Dec 2006, stewbawka wrote:

> code in the next action run?  
> No; the redirect will trigger the action. If you’re not finding what  
> you expect, something else is happening, like a validation failing.  
> (Check your log files too.)

David

–  
Q. What’s a good holiday present for the serious Rails developer?  
A. RUBY FOR RAILS by David A. Black ([Ruby for Rails](http://www.manning.com/black))  
aka The Ruby book for Rails developers!  
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))
