# Route errors in functional tests

**URL:** <https://www.ruby-forum.com/t/route-errors-in-functional-tests/91285>\
**Category:** Rails\
**Created:** [April 6, 2007, 8:36am UTC](https://www.ruby-forum.com/t/route-errors-in-functional-tests/91285 "2007-04-06T08:36:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chet\_sanders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@chet\_sanders](https://www.ruby-forum.com/u/chet_sanders)\
**Post date:** [April 6, 2007, 8:36am UTC](https://www.ruby-forum.com/t/route-errors-in-functional-tests/91285/1 "2007-04-06T08:36:04Z")

</div>

I have a rails app that will show details for a particular project. I am  
hoping to make it easy on users by providing subdomains for each project  
and specifying the project ID in the routes file as follows -

map.connect ‘:controller/:action/:id’,  
:defaults =\> { :action =\> ‘list’, :id =\> nil },  
:project\_id =\> 3 # Specify the project ID here.

So once my application gets a request, it has params[:project\_id]  
defined, that I can use to filter the content made available to users.

This works fine in development and production mode. But functional tests  
for controllers don’t like this and barf with - “No route matches” for  
any action.

Any thoughts? comments?

The ugly workaround I have is to add this to routes.rb above the above  
route -

if ENV[‘RAILS\_ENV’] == ‘test’  
map.connect “:controller/:action/:id”  
end

and call every ‘get’ in functional controller as

get :action, {:project\_id =\> 3}

This works but is Not DRY and Not fun.

What am I missing here?

---

<div class="post-metadata">

**Author:** ![chet\_sanders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@chet\_sanders](https://www.ruby-forum.com/u/chet_sanders)\
**Post date:** [April 6, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/route-errors-in-functional-tests/91285/2 "2007-04-06T21:08:39Z")

</div>

Chet Sanders wrote:

> I have a rails app that will show details for a particular project. I am  
> hoping to make it easy on users by providing subdomains for each project  
> and specifying the project ID in the routes file as follows -
> 
> map.connect ‘:controller/:action/:id’,  
> :defaults =\> { :action =\> ‘list’, :id =\> nil },  
> :project\_id =\> 3 # Specify the project ID here.
> 
> So once my application gets a request, it has params[:project\_id]  
> defined, that I can use to filter the content made available to users.
> 
> This works fine in development and production mode. But functional tests  
> for controllers don’t like this and barf with - “No route matches” for  
> any action.
> 
> Any thoughts? comments?

Sorry don’t have an answer for you. But I had a similar problem before.  
Our solution was to test controllers in integration tests.
