From 69e87f5994f74eef02fdfd7912ae81a334d74218 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 26 Mar 2013 12:19:46 +0100 Subject: [PATCH] routing shorthand syntax works with multiple paths Closes #9913. We need to expand the match shorthand syntax for every path. --- actionpack/lib/action_dispatch/routing/mapper.rb | 11 ++++++----- actionpack/test/dispatch/routing_test.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f9893f2d854e0..f9cdfd5cf032f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1369,11 +1369,6 @@ def match(path, *rest) paths = [path] + rest end - path_without_format = path.to_s.sub(/\(\.:format\)$/, '') - if using_match_shorthand?(path_without_format, options) - options[:to] ||= path_without_format.gsub(%r{^/}, "").sub(%r{/([^/]*)$}, '#\1') - end - options[:anchor] = true unless options.key?(:anchor) if options[:on] && !VALID_ON_OPTIONS.include?(options[:on]) @@ -1383,6 +1378,12 @@ def match(path, *rest) paths.each do |_path| route_options = options.dup route_options[:path] ||= _path if _path.is_a?(String) + + path_without_format = _path.to_s.sub(/\(\.:format\)$/, '') + if using_match_shorthand?(path_without_format, route_options) + route_options[:to] ||= path_without_format.gsub(%r{^/}, "").sub(%r{/([^/]*)$}, '#\1') + end + decomposed_match(_path, route_options) end self diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6dde183222e17..6eb9d019dfa77 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1149,6 +1149,20 @@ def test_match_shorthand_inside_namespace assert_equal 'account#shorthand', @response.body end + def test_match_shorthand_with_multiple_paths_inside_namespace + draw do + namespace :proposals do + put 'activate', 'inactivate' + end + end + + put '/proposals/activate' + assert_equal 'proposals#activate', @response.body + + put '/proposals/inactivate' + assert_equal 'proposals#inactivate', @response.body + end + def test_match_shorthand_inside_namespace_with_controller draw do namespace :api do