diff options
author | Chris Carter <chris.carter@unboxedconsulting.com> | 2016-09-20 10:42:26 +0100 |
---|---|---|
committer | Chris Carter <chris.carter@unboxedconsulting.com> | 2016-10-03 09:52:14 +0100 |
commit | 0b32e2dff353ceb9bc463787c5897ecae7302ab7 (patch) | |
tree | b549472a55b336e05bbad52b98630f360f53f63f /actionpack/test/dispatch/routing_test.rb | |
parent | 2d6c14bca25c5629e431a802c3053bad1e378fcc (diff) | |
download | rails-0b32e2dff353ceb9bc463787c5897ecae7302ab7.tar.gz rails-0b32e2dff353ceb9bc463787c5897ecae7302ab7.tar.bz2 rails-0b32e2dff353ceb9bc463787c5897ecae7302ab7.zip |
Show an "unmatched constraints" error for mismatching and present params
Currently a misleading "missing required keys" error is thrown when a param
fails to match the constraints of a particular route. This commit ensures that
these params are recognised as unmatching rather than missing.
Note: this means that a different error message will be provided between
optimized and non-optimized path helpers, due to the fact that the former does
not check constraints when matching routes.
Fixes #26470.
Diffstat (limited to 'actionpack/test/dispatch/routing_test.rb')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6ba52e37b6..9b6e060955 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -4684,22 +4684,25 @@ class TestUrlGenerationErrors < ActionDispatch::IntegrationTest include Routes.url_helpers - test "url helpers raise a helpful error message when generation fails" do + test "url helpers raise a 'missing keys' error for a nil param with optimized helpers" do url, missing = { action: "show", controller: "products", id: nil }, [:id] - message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + 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 + end + + test "url helpers raise a 'constraint failure' error for a nil param with non-optimized helpers" do + url, missing = { action: "show", controller: "products", id: nil }, [:id] + message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" - # Non-optimized url helper error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil) } assert_equal message, error.message end - test "url helpers raise message with mixed parameters when generation fails " do + test "url helpers raise message with mixed parameters when generation fails" do url, missing = { action: "show", controller: "products", id: nil, "id"=>"url-tested" }, [:id] - message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" # Optimized url helper error = assert_raises(ActionController::UrlGenerationError) { product_path(nil, "id"=>"url-tested") } |