# Understanding how methods are made available within controller tests

**URL:** <https://www.ruby-forum.com/t/understanding-how-methods-are-made-available-within-controller-tests/162743>\
**Category:** Rails\
**Created:** [March 13, 2009, 10:41am UTC](https://www.ruby-forum.com/t/understanding-how-methods-are-made-available-within-controller-tests/162743 "2009-03-13T10:41:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![karl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@karl](https://www.ruby-forum.com/u/karl)\
**Post date:** [March 13, 2009, 10:41am UTC](https://www.ruby-forum.com/t/understanding-how-methods-are-made-available-within-controller-tests/162743/1 "2009-03-13T10:41:40Z")

</div>

Being new to rails and ruby, I am trying to figure out how things fit  
together. In particular i am trying to understand how attributes such  
as “session” and “cookies” are made available to Controller tests.  
Specifically I am working on a test from the RailsSpace book which  
extends Test::Unit::TestCase and only imports the module  
ApplicationHelper while attributes such as cookies and session are  
defined within the ActionController::TestProcess module. I cannot  
figure out how module ActionController::TestProcess is included within  
the UserControllerTest.

require File.dirname( **FILE** ) + ‘/…/test\_helper’  
require ‘user\_controller’

# Re-raise errors caught by the controller.

class UserController; def rescue\_action(e) raise e end; end

class UserControllerTest \< Test::Unit::TestCase  
include ApplicationHelper

…  
…  
def authorize(user)  
@request.session[:user\_id] = user.id  
end

def friendly\_url\_forwarding\_aux(test\_page, protected\_page, user)  
get protected\_page  
assert\_response :redirect  
assert\_redirected\_to :action =\> “login”  
post test\_page, :user =\> user  
assert\_response :redirect  
assert\_redirected\_to :action =\> protected\_page  
assert\_nil session[:protected\_page]  
end

def cookie\_value(symbol)  
cookies[symbol.to\_s].value.first  
end

def cookie\_expires(symbol)  
cookies[symbol.to\_s].expires  
end

thx.

-karl

---

<div class="post-metadata">

**Author:** ![karl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@karl](https://www.ruby-forum.com/u/karl)\
**Post date:** [March 13, 2009, 6:56pm UTC](https://www.ruby-forum.com/t/understanding-how-methods-are-made-available-within-controller-tests/162743/2 "2009-03-13T18:56:38Z")

</div>

Makes sense. My only confusion is I thought that in ruby methods and  
attributes can be imported to a class either through inheritance or  
importing a module. In this case, these extra attributes such as  
“session”  
or “cookies” do not exist within the parent class nor the imported  
module.  
Is rails including extra modules within my classes at runtime?  
Thanks for your help!

-karl

On Fri, Mar 13, 2009 at 5:53 AM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![karl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@karl](https://www.ruby-forum.com/u/karl)\
**Post date:** [March 13, 2009, 10:54am UTC](https://www.ruby-forum.com/t/understanding-how-methods-are-made-available-within-controller-tests/162743/3 "2009-03-13T10:54:34Z")

</div>

On Mar 13, 3:38 am, Karl [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Being new to rails and ruby, I am trying to figure out how things fit  
> together. In particular i am trying to understand how attributes such  
> as “session” and “cookies” are made available to Controller tests.  
> Specifically I am working on a test from the RailsSpace book which  
> extends Test::Unit::TestCase and only imports the module  
> ApplicationHelper while attributes such as cookies and session are  
> defined within the ActionController::TestProcess module. I cannot  
> figure out how module ActionController::TestProcess is included within  
> the UserControllerTest.

The test\_helper file that you require at the top of your test file in  
turn requires a bunch of stuff, in particular a file that adds those  
methods to test cases.

Fred

---

<div class="post-metadata">

**Author:** ![karl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@karl](https://www.ruby-forum.com/u/karl)\
**Post date:** [March 14, 2009, 1:48pm UTC](https://www.ruby-forum.com/t/understanding-how-methods-are-made-available-within-controller-tests/162743/4 "2009-03-14T13:48:26Z")

</div>

On Mar 13, 5:55 pm, Karl B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Makes sense. My only confusion is I thought that in ruby methods and  
> attributes can be imported to a class either through inheritance or  
> importing a module. In this case, these extra attributes such as “session”  
> or “cookies” do not exist within the parent class nor the imported module.  
> Is rails including extra modules within my classes at runtime?  
> Thanks for your help!

You can also just reopen a class and add methods to it. if my memory  
is correct that is what rails does to Test::Unit::TestCase.

Fred
