diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-05 10:05:54 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-05 10:27:46 +0000 |
commit | 892c539591c001285792b7865fe5d70846b0041b (patch) | |
tree | 0bf8916e63ecb5eaefd48cb3ac098f7a975f0147 /actionpack/test | |
parent | b9efc74f9e63e76f121204a96073d2f5582f66e6 (diff) | |
download | rails-892c539591c001285792b7865fe5d70846b0041b.tar.gz rails-892c539591c001285792b7865fe5d70846b0041b.tar.bz2 rails-892c539591c001285792b7865fe5d70846b0041b.zip |
Show full route constraints in error message
When an optimized helper fails to generate, show the full route constraints
in the error message. Previously it would only show the contraints that were
required as part of the path.
Fixes #13592
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index fad09d309a..d41b94511a 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3708,3 +3708,28 @@ class TestRedirectRouteGeneration < ActionDispatch::IntegrationTest end end end + +class TestUrlGenerationErrors < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw do + get "/products/:id" => 'products#show', :as => :product + end + end + + def app; Routes end + + include Routes.url_helpers + + test "url helpers raise a helpful error message whem generation fails" do + url, missing = { action: 'show', controller: 'products', id: nil }, [:id] + message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + + # Optimized url helper + error = assert_raises(ActionController::UrlGenerationError){ product_path(nil) } + assert_equal message, error.message + + # Non-optimized url helper + error = assert_raises(ActionController::UrlGenerationError, message){ product_path(id: nil) } + assert_equal message, error.message + end +end |