diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-03 06:48:04 -0700 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-03 06:48:04 -0700 |
commit | 148b9ccbb537f99f35374a49aad929aebf8d6ff2 (patch) | |
tree | 02144c13cf7198b3f0a0c8ba4396ba9fa25ad5dc | |
parent | a957cb7f378e1c1b6b21e862fed095c6e72745ac (diff) | |
parent | 69e87f5994f74eef02fdfd7912ae81a334d74218 (diff) | |
download | rails-148b9ccbb537f99f35374a49aad929aebf8d6ff2.tar.gz rails-148b9ccbb537f99f35374a49aad929aebf8d6ff2.tar.bz2 rails-148b9ccbb537f99f35374a49aad929aebf8d6ff2.zip |
Merge pull request #9932 from senny/9913_routing_problem
routing bugfixes when matching multiple paths
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 20 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 29 |
2 files changed, 41 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 399f6529a7..45d2d3346e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -589,8 +589,7 @@ module ActionDispatch private def map_method(method, args, &block) options = args.extract_options! - options[:via] = method - options[:path] ||= args.first if args.first.is_a?(String) + options[:via] = method match(*args, options, &block) self end @@ -1370,18 +1369,23 @@ module ActionDispatch 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]) raise ArgumentError, "Unknown scope #{on.inspect} given to :on" end - paths.each { |_path| decomposed_match(_path, options.dup) } + 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 end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 643c83dc91..29703dd5b1 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1134,6 +1134,21 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal 'projects#info', @response.body end + def test_match_with_many_paths_containing_a_slash + draw do + get 'get/first', 'get/second', 'get/third', :to => 'get#show' + end + + get '/get/first' + assert_equal 'get#show', @response.body + + get '/get/second' + assert_equal 'get#show', @response.body + + get '/get/third' + assert_equal 'get#show', @response.body + end + def test_match_shorthand_with_no_scope draw do get 'account/overview' @@ -1156,6 +1171,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest 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 |