# Testing controller modules

**URL:** <https://www.ruby-forum.com/t/testing-controller-modules/111815>\
**Category:** Rails\
**Created:** [August 11, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/testing-controller-modules/111815 "2007-08-11T15:07:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [August 11, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/testing-controller-modules/111815/1 "2007-08-11T15:07:04Z")

</div>

Hello,

I have a controller that defines a module and I’m wondering how I can  
write a functional test for methods w/in the module.

Here’s the basic structure of the controller module blog\_controller:

```auto
require 'hmac/hmac-sha2'

module BlogController
  PAGEXI_HMAC_SHA256_KEY = "sdfqaasdfwfa3rq32aq"
  PAGEXI_HMAC_SHA256_AUTHOR_KEY = "sooloo"

  def combined
    render :partial => "/blog/page_object_combined"
  end

  #etc...
end

```

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [August 13, 2007, 9:43am UTC](https://www.ruby-forum.com/t/testing-controller-modules/111815/2 "2007-08-13T09:43:16Z")

</div>

Clem R. wrote:

> module BlogController  
> [/code]
> 
> Any ideas?
> 
> Thanks!

I usually set up a test for that module, and in the test file define a  
Dummy Controller that includes the module and has only the most basic  
functionality (e.g. an action with render :text “hello world”). Have a  
look at some of the tests in Rails itself, e.g. the redirect tests in  
rails/action\_pack/test/controller/redirect\_test.rb

You can also do some unit testing of the Dummy Controller instance  
(that’s available via the @controller instance variable – e.g.  
@controller.respond\_to?(:combined). If you do a bit of googling for  
something like “testing application controller” there’s some info  
somewhere on how to test methods defined in the AC, and that should  
steer you in the right direction also.

Hope this helps

Chris

## –

Autopendium :: Stuff about old cars  
[http://autopendium.com](http://autopendium.com)
