From 0b6175ac2df96ebfca1baac89c20deaa13e61142 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 1 Aug 2012 15:33:15 -0500 Subject: Add Missing Keys from Journey on failed URL format Many named routes have keys that are required to successfully resolve. If a key is left off like this: <%= link_to 'user', user_path %> This will produce an error like this: No route matches {:action=>"show", :controller=>"users"} Since we know that the :id is missing, we can add extra debugging information to the error message. No route matches {:action=>"show", :controller=>"users"} missing required keys: [:id] This will help new and seasoned developers look closer at their parameters. I've also subclassed the routing error to be clear that this error is a result of attempting to generate a url and not because the user is trying to visit a bad url. While this may sound trivial this error message is misleading and confuses most developers. The important part isn't what's in the options its's what's missing. Adding this information to the error message will make debugging much more obvious. This is the sister pull request of https://github.com/rails/journey/pull/44 which will be required to get they missing keys into the correct error message. Example Development Error in Rails: http://cl.ly/image/3S0T0n1T3421 --- actionpack/test/controller/routing_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 57ab325683..f0430e516f 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -275,7 +275,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase mount lambda {} => "/foo" end - assert_raises(ActionController::RoutingError) do + assert_raises(ActionController::UrlGenerationError) do url_for(rs, :controller => "omg", :action => "lol") end end @@ -514,7 +514,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase rs.draw do get 'post/:id' => 'post#show', :constraints => { :id => /\d+/ }, :as => 'post' end - assert_raise(ActionController::RoutingError) do + assert_raise(ActionController::UrlGenerationError) do url_for(rs, { :controller => 'post', :action => 'show', :bad_param => "foo", :use_route => "post" }) end end @@ -594,7 +594,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase assert_equal '/post/10', url_for(rs, { :controller => 'post', :action => 'show', :id => 10 }) - assert_raise ActionController::RoutingError do + assert_raise(ActionController::UrlGenerationError) do url_for(rs, { :controller => 'post', :action => 'show' }) end end @@ -760,7 +760,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase get 'foos/:id' => 'foos#show', :as => 'foo_with_requirement', :constraints => { :id => /\d+/ } end - assert_raise(ActionController::RoutingError) do + assert_raise(ActionController::UrlGenerationError) do setup_for_named_route.send(:foo_with_requirement_url, "I am Against the constraints") end end @@ -1051,7 +1051,7 @@ class RouteSetTest < ActiveSupport::TestCase set.draw do get "/people" => "missing#index" end - + assert_raise(ActionController::RoutingError) { set.recognize_path("/people", :method => :get) } @@ -1459,7 +1459,7 @@ class RouteSetTest < ActiveSupport::TestCase url = url_for(set, { :controller => 'pages', :action => 'show', :name => 'david' }) assert_equal "/page/david", url - assert_raise ActionController::RoutingError do + assert_raise(ActionController::UrlGenerationError) do url_for(set, { :controller => 'pages', :action => 'show', :name => 'davidjamis' }) end url = url_for(set, { :controller => 'pages', :action => 'show', :name => 'JAMIS' }) -- cgit v1.2.3