# Forcing the Loading of Named Routes

**URL:** <https://www.ruby-forum.com/t/forcing-the-loading-of-named-routes/147078>\
**Category:** Rails\
**Created:** [August 28, 2008, 10:42am UTC](https://www.ruby-forum.com/t/forcing-the-loading-of-named-routes/147078 "2008-08-28T10:42:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [August 28, 2008, 10:42am UTC](https://www.ruby-forum.com/t/forcing-the-loading-of-named-routes/147078/1 "2008-08-28T10:42:08Z")

</div>

Hi all,

I have a spec for my controller (and its routing) that looks like this:

```
  describe "named routes" do

    before do
      # mini-hack: need a GET before the named routes are loaded
      get :index
    end

    it "admin_venue_merges_path.should == '/admin/venue_merges'" do
      admin_venue_merges_path.should == "/admin/venue_merges"
    end

  end

```

Trouble is, I don’t actually need an index action on this particular  
controller - it’s just there so that I can spin up whatever the code is  
within ActionPack that loads those named route methods.

What I’d prefer to do is directly call ActionController or whatever and  
tell it to load the named routes.

I’m fairly new to ruby and find the source code to ActionPack pretty  
overwhelming.

Can anyone more au fait with the rails source tell me how I might  
achieve this?

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [August 28, 2008, 2:48pm UTC](https://www.ruby-forum.com/t/forcing-the-loading-of-named-routes/147078/2 "2008-08-28T14:48:34Z")

</div>

I recommend generating an rspec\_scaffold. It gives some nice examples  
for  
model, controller and view specs.

$ script/generate rspec\_scaffold Person name:string age:integer

gives this for verifying routing:

describe PeopleController do  
describe “route generation” do  
it “should map #index” do  
route\_for(:controller =\> “people”, :action =\> “index”).should ==  
“/people”  
end  
…  
end  
…  
end

Regards,  
Craig

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [August 28, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/forcing-the-loading-of-named-routes/147078/3 "2008-08-28T16:15:44Z")

</div>

Craig D. wrote:

> I recommend generating an rspec\_scaffold.  
> gives this for verifying routing:
> 
> describe PeopleController do  
> describe “route generation” do  
> it “should map #index” do  
> route\_for(:controller =\> “people”, :action =\> “index”).should ==  
> “/people”  
> end  
> …  
> end  
> …  
> end  
> Okay sure, but if I want to test the _named route_, for example if I  
> want to put a route into a namespace, how do I write a test for that?
