Skip to content

Commit

Permalink
routing shorthand syntax works with multiple paths
Browse files Browse the repository at this point in the history
Closes #9913.

We need to expand the match shorthand syntax for every path.
  • Loading branch information
senny committed Mar 26, 2013
1 parent d5f4cac commit 69e87f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -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])
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 69e87f5

Please sign in to comment.