aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2016-10-03 11:41:38 +0100
committerGitHub <noreply@github.com>2016-10-03 11:41:38 +0100
commit8058ece4feea7fb8feed1d0cfc44c6065c773127 (patch)
treeb549472a55b336e05bbad52b98630f360f53f63f /actionpack/test
parent2d6c14bca25c5629e431a802c3053bad1e378fcc (diff)
parent0b32e2dff353ceb9bc463787c5897ecae7302ab7 (diff)
downloadrails-8058ece4feea7fb8feed1d0cfc44c6065c773127.tar.gz
rails-8058ece4feea7fb8feed1d0cfc44c6065c773127.tar.bz2
rails-8058ece4feea7fb8feed1d0cfc44c6065c773127.zip
Merge pull request #26555 from chriscarter90/unmatched-constraint-routing-messages
Show an "unmatched constraints" error when params fail to match constraints
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/dispatch/routing_test.rb15
-rw-r--r--actionpack/test/journey/router_test.rb2
2 files changed, 10 insertions, 7 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") }
diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb
index 2b99637f56..7b5916eb72 100644
--- a/actionpack/test/journey/router_test.rb
+++ b/actionpack/test/journey/router_test.rb
@@ -297,7 +297,7 @@ module ActionDispatch
}
request_parameters = primarty_parameters.merge(redirection_parameters).merge(missing_parameters)
- message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect} missing required keys: #{[missing_key.to_sym].inspect}"
+ message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect}, missing required keys: #{[missing_key.to_sym].inspect}"
error = assert_raises(ActionController::UrlGenerationError) do
@formatter.generate(