Topic: [RSpec] resource setting as root.

I'm specing the routes for my app. This probably belongs in the rails section since I don't know how to write routes probably.

describe TicketsController, "#route_for" do

  it "should map { :controller => 'tickets', :action => 'index' } to /" do
    route_for(:controller => "tickets", :action => "index").should == "/"
  end
end


6)
'TicketsController#route_for should map { :controller => 'tickets', :action => 'index' } to /' FAILED
expected "/", got "/tickets" (using ==)
./spec/controllers/tickets_controller_spec.rb:6:
script/spec:4:


So the error is obvious, but I don't know how to write the route to look at the root. I currently have Tickets setup as a default resource.

Re: [RSpec] resource setting as root.

Try this:

# near top of routes.rb
map.home '/', :controller => 'tickets', :action => 'index'

Railscasts - Free Ruby on Rails Screencasts

Re: [RSpec] resource setting as root.

I had tried that before.
I didn't realize it was working, but I think I left something out.
I want all routes generated by my resource to point to / instead of /tickets.

/usr/local/bin/ruby -S script/spec -O spec/spec.opts  spec/controllers/tickets_controller_spec.rb
FFFFF.

1)
'TicketsController#route_for should map { :controller => 'tickets', :action => 'destroy', :id => 1} to /1' FAILED
expected "/1", got "/tickets/destroy/1" (using ==)
./spec/controllers/tickets_controller_spec.rb:26:
script/spec:4:

2)
'TicketsController#route_for should map { :controller => 'tickets', :action => 'update', :id => 1} to /1' FAILED
expected "/1", got "/tickets/update/1" (using ==)
./spec/controllers/tickets_controller_spec.rb:22:
script/spec:4:

3)
'TicketsController#route_for should map { :controller => 'tickets', :action => 'edit', :id => 1 } to /1;edit' FAILED
expected "/1;edit", got "/tickets/edit/1" (using ==)
./spec/controllers/tickets_controller_spec.rb:18:
script/spec:4:

4)
'TicketsController#route_for should map { :controller => 'tickets', :action => 'show', :id => 1 } to /1' FAILED
expected "/1", got "/tickets/show/1" (using ==)
./spec/controllers/tickets_controller_spec.rb:14:
script/spec:4:

5)
'TicketsController#route_for should map { :controller => 'tickets', :action => 'new' } to /new' FAILED
expected "/new", got "/tickets/new" (using ==)
./spec/controllers/tickets_controller_spec.rb:10:
script/spec:4:

Finished in 0.153081 seconds

6 examples, 5 failures

Re: [RSpec] resource setting as root.

I don't think that's possible with map.resources. You'll have to create a custom route for each action.

Out of curiosity, why do you want to do this?

Railscasts - Free Ruby on Rails Screencasts

Re: [RSpec] resource setting as root.

I wanted:

www.example.com/tickets

to be:

www.example.com/

but I didn't think too hard why
www.example.com/tickets/1 had to be www.example.com/1

It would probably make more sense to leave show and edit as
www.example.com/tickets/1 and www.example.com/tickets/1;edit

Not enough hard thinking. tongue

While running in development mode

map.home '/', :controller => 'tickets', :action => 'index'

Doesn't bring me to tickets index but still the default application page with rails.

Last edited by OmenKing (2007-06-14 15:25:12)