Skip to content

Commit

Permalink
Remove hardcoded number_of_capturesin ControllerSegment to allow rege…
Browse files Browse the repository at this point in the history
…xp requirements with capturing parentheses

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1887 state:committed]
  • Loading branch information
pixeltrix authored and NZKoz committed Feb 22, 2009
1 parent fc09ebc commit f7a0a39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 0 additions & 4 deletions actionpack/lib/action_controller/routing/segments.rb
Expand Up @@ -244,10 +244,6 @@ def regexp_chunk
"(?i-:(#{(regexp || Regexp.union(*possible_names)).source}))"
end

def number_of_captures
1
end

# Don't URI.escape the controller name since it may contain slashes.
def interpolation_chunk(value_code = local_name)
"\#{#{value_code}.to_s}"
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -852,6 +852,15 @@ def test_route_with_regexp_for_controller
assert_equal '/content/foo', rs.generate(:controller => "content", :action => "foo")
end

def test_route_with_regexp_and_captures_for_controller
rs.draw do |map|
map.connect ':controller/:action/:id', :controller => /admin\/(accounts|users)/
end
assert_equal({:controller => "admin/accounts", :action => "index"}, rs.recognize_path("/admin/accounts"))
assert_equal({:controller => "admin/users", :action => "index"}, rs.recognize_path("/admin/users"))
assert_raises(ActionController::RoutingError) { rs.recognize_path("/admin/products") }
end

def test_route_with_regexp_and_dot
rs.draw do |map|
map.connect ':controller/:action/:file',
Expand Down

0 comments on commit f7a0a39

Please sign in to comment.