mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix failing test missed for the past year :(
When optimized path helpers were re-introduced ind7014bc
the test added ina328f2f
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.
This commit is contained in:
parent
96310f69e1
commit
74722d66d3
2 changed files with 18 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -22,7 +22,7 @@ module ActionDispatch
|
|||
x = Class.new {
|
||||
include rs.url_helpers
|
||||
}
|
||||
assert_raises ActionController::RoutingError do
|
||||
assert_raises ActionController::UrlGenerationError do
|
||||
x.new.pond_duck_path Duck.new
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue