Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use next instead of break; avoid terminating whole loop #27499

Merged
merged 1 commit into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/journey/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate(name, options, path_parameters, parameterize = nil)

route.parts.reverse_each do |key|
break if defaults[key].nil? && parameterized_parts[key].present?
break if parameterized_parts[key].to_s != defaults[key].to_s
next if parameterized_parts[key].to_s != defaults[key].to_s
break if required_parts.include?(key)

parameterized_parts.delete(key)
Expand Down
21 changes: 21 additions & 0 deletions actionpack/test/controller/url_for_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,27 @@ def test_url_for_with_array_is_unmodified
end
end

def test_default_params_first_empty
with_routing do |set|
set.draw do
get "(:param1)/test(/:param2)" => "index#index",
defaults: {
param1: 1,
param2: 2
},
constraints: {
param1: /\d*/,
param2: /\d+/
}
end

kls = Class.new { include set.url_helpers }
kls.default_url_options[:host] = "www.basecamphq.com"

assert_equal "http://www.basecamphq.com/test", kls.new.url_for(controller: "index", param1: "1")
end
end

private
def extract_params(url)
url.split("?", 2).last.split("&").sort
Expand Down