diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-17 08:56:34 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-17 08:56:34 +0100 |
commit | 74722d66d332d1d768459d8b510cc082fe3d5618 (patch) | |
tree | 88fb80cfe659cc83407be2015f8b624e4afb83cf /actionpack/lib/action_dispatch | |
parent | 96310f69e1fd4bf0d744ed9599df895ef1fcf2d1 (diff) | |
download | rails-74722d66d332d1d768459d8b510cc082fe3d5618.tar.gz rails-74722d66d332d1d768459d8b510cc082fe3d5618.tar.bz2 rails-74722d66d332d1d768459d8b510cc082fe3d5618.zip |
Fix failing test missed for the past year :(
When optimized path helpers were re-introduced in d7014bc the test added
in a328f2f broke but no-one noticed because it wasn't being run by the
test suite.
Fix the test by checking for nil values or empty strings after the args
have been parameterized.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 3ae9f92c0b..fca663b2a3 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -184,12 +184,27 @@ module ActionDispatch def optimized_helper(args) path = @string_route.dup klass = Journey::Router::Utils + parameterized_args = args.map(&:to_param) + missing_keys = [] - @path_parts.zip(args) do |part, arg| + parameterized_args.each_with_index do |arg, index| + if arg.nil? || arg.empty? + missing_keys << @path_parts[index] + end + end + + unless missing_keys.empty? + message = "No route matches #{Hash[@path_parts.zip(args)].inspect}" + message << " missing required keys: #{missing_keys.inspect}" + + raise ActionController::UrlGenerationError, message + end + + @path_parts.zip(parameterized_args) do |part, arg| # Replace each route parameter # e.g. :id for regular parameter or *path for globbing # with ruby string interpolation code - path.gsub!(/(\*|:)#{part}/, klass.escape_fragment(arg.to_param)) + path.gsub!(/(\*|:)#{part}/, klass.escape_fragment(arg)) end path end |