I'm using rspec-rails (2.8.1) and rails 3.1.3.
I'm trying to test routes for my Admin::ZonesController. I have verified the route exists in both the browser and by running rake routes
. I am not using ActiveRecord (if that matters). When I run the routing spec, it tells me:
ActionController::RoutingError: No route matches "/admin/zones/new"
Here is the test (spec/routing/admin/zones_routing_spec.rb):
require 'spec_helper'
describe "routing to zones" do
it "routes /admin/zones/new to admin/zones#new" do
{ :get => "/admin/zones/new" }.should route_to(
:controller => "admin/zones",
:action => "new"
)
end
end
Here is the controller action whose route I am trying to test (admin/zones#new):
class Admin::ZonesController < Admin::BaseController
before_filter :instantiate_variables
def new
@zone = Zone.new
@campaign = Campaign.new
@rules = [Rule.new]
end
end
Running rake routes
gives me this:
POST /hooks/:resource(.:format) {:controller=>"hooks", :action=>"create"}
POST /services/:service/:method(.:format) {:controller=>"services", :action=>"create"}
admin_zones GET /admin/zones(.:format) {:action=>"index", :controller=>"admin/zones"}
POST /admin/zones(.:format) {:action=>"create", :controller=>"admin/zones"}
new_admin_zone GET /admin/zones/new(.:format) {:action=>"new", :controller=>"admin/zones"}
edit_admin_zone GET /admin/zones/:id/edit(.:format) {:action=>"edit", :controller=>"admin/zones"}
admin_zone GET /admin/zones/:id(.:format) {:action=>"show", :controller=>"admin/zones"}
PUT /admin/zones/:id(.:format) {:action=>"update", :controller=>"admin/zones"}
DELETE /admin/zones/:id(.:format) {:action=>"destroy", :controller=>"admin/zones"}
admin_widgets GET /admin/widgets(.:format) {:action=>"index", :controller=>"admin/widgets"}
POST /admin/widgets(.:format) {:action=>"create", :controller=>"admin/widgets"}
new_admin_widget GET /admin/widgets/new(.:format) {:action=>"new", :controller=>"admin/widgets"}
edit_admin_widget GET /admin/widgets/:id/edit(.:format) {:action=>"edit", :controller=>"admin/widgets"}
admin_widget GET /admin/widgets/:id(.:format) {:action=>"show", :controller=>"admin/widgets"}
PUT /admin/widgets/:id(.:format) {:action=>"update", :controller=>"admin/widgets"}
DELETE /admin/widgets/:id(.:format) {:action=>"destroy", :controller=>"admin/widgets"}
zones GET /zones(.:format) {:action=>"index", :controller=>"zones"}
POST /zones(.:format) {:action=>"create", :controller=>"zones"}
new_zone GET /zones/new(.:format) {:action=>"new", :controller=>"zones"}
edit_zone GET /zones/:id/edit(.:format) {:action=>"edit", :controller=>"zones"}
zone GET /zones/:id(.:format) {:action=>"show", :controller=>"zones"}
PUT /zones/:id(.:format) {:action=>"update", :controller=>"zones"}
DELETE /zones/:id(.:format) {:action=>"destroy", :controller=>"zones"}
root / {:controller=>"admin/zones", :action=>"new"}
My routes.rb looks like this:
D2CModularPlatform::Application.routes.draw do
post "/hooks/:resource" => "hooks#create"
post "/services/:service/:method" => "services#create"
namespace :admin do
resources :zones
resources :widgets
end
resources :zones
root :to => "admin/zones#new"
end
My controllers dir looks like this:
- controllers
- admin
- base_controller
- widgets_controller
- zones_controller
- application_controller
- hooks_controller
- services_controller
- zones_controller
- admin
My spec/routing dir looks like this:
- spec/routing
- admin
- zones_routing_spec
- hooks_routing_spec
- services_routing_spec
- zones_routing_spec
- admin