Permalink
Browse files

Merge pull request #2549 from trek/RoutingErrorForMissingControllers

When a route references a missing controller, raise ActionController::RoutingError with clearer message
  • Loading branch information...
2 parents d2901f0 + dde5b87 commit 513a0525c24c2944630acfa465b22cd2f4601adf @tenderlove tenderlove committed May 21, 2012
Showing with 17 additions and 3 deletions.
  1. +7 −3 actionpack/lib/action_dispatch/routing/route_set.rb
  2. +10 −0 actionpack/test/controller/routing_test.rb
@@ -663,9 +663,13 @@ def recognize_path(path, environment = {})
dispatcher = dispatcher.app
end
- if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
- dispatcher.prepare_params!(params)
- return params
+ if dispatcher.is_a?(Dispatcher)
+ if dispatcher.controller(params, false)
+ dispatcher.prepare_params!(params)
+ return params
+ else
+ raise ActionController::RoutingError, "A route matches #{path.inspect}, but references missing controller: #{params[:controller].camelize}Controller"
+ end
end
end
@@ -1037,6 +1037,16 @@ def test_route_constraints_with_options_method_condition_is_valid
end
end
+ def test_route_error_with_missing_controller
+ set.draw do
+ get "/people" => "missing#index"
+ end
+
+ assert_raise(ActionController::RoutingError) {
+ set.recognize_path("/people", :method => :get)
+ }
+ end
+
def test_recognize_with_encoded_id_and_regex
set.draw do
get 'page/:id' => 'pages#show', :id => /[a-zA-Z0-9\+]+/

0 comments on commit 513a052

Please sign in to comment.