Skip to content

Commit

Permalink
Move implicit nested call before options handling so that nested cons…
Browse files Browse the repository at this point in the history
…traints work [#5513 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
pixeltrix authored and josevalim committed Sep 1, 2010
1 parent 3b6d7f0 commit 9441eab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
16 changes: 7 additions & 9 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -909,6 +909,11 @@ def apply_common_behavior_for(method, resources, options, &block)
return true
end

if resource_scope?
nested { send(method, resources.pop, options, &block) }
return true
end

options.keys.each do |k|
(options[:constraints] ||= {})[k] = options.delete(k) if options[k].is_a?(Regexp)
end
Expand All @@ -925,13 +930,6 @@ def apply_common_behavior_for(method, resources, options, &block)
options.merge!(scope_action_options) if scope_action_options?
end

if resource_scope?
nested do
send(method, resources.pop, options, &block)
end
return true
end

false
end

Expand Down Expand Up @@ -1017,11 +1015,11 @@ def nested_options
end

def id_constraint?
@scope[:id].is_a?(Regexp) || (@scope[:constraints] && @scope[:constraints][:id].is_a?(Regexp))
@scope[:constraints] && @scope[:constraints][:id].is_a?(Regexp)
end

def id_constraint
@scope[:id] || @scope[:constraints][:id]
@scope[:constraints][:id]
end

def canonical_action?(action, flag)
Expand Down
18 changes: 18 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -448,6 +448,10 @@ def self.matches?(request)
:filename => /(.+)/,
:as => :purchase

resources :lists, :id => /([A-Za-z0-9]{25})|default/ do
resources :todos, :id => /\d+/
end

scope '/countries/:country', :constraints => lambda { |params, req| %[all France].include?(params[:country]) } do
match '/', :to => 'countries#index'
match '/cities', :to => 'countries#cities'
Expand Down Expand Up @@ -2110,6 +2114,20 @@ def test_named_character_classes_in_regexp_constraints
assert_equal '/purchases/315004be7e/Ruby_on_Rails_3.pdf', purchase_path(:token => '315004be7e', :filename => 'Ruby_on_Rails_3.pdf')
end

def test_nested_resource_constraints
get '/lists/01234012340123401234fffff'
assert_equal 'lists#show', @response.body
assert_equal '/lists/01234012340123401234fffff', list_path(:id => '01234012340123401234fffff')

get '/lists/01234012340123401234fffff/todos/1'
assert_equal 'todos#show', @response.body
assert_equal '/lists/01234012340123401234fffff/todos/1', list_todo_path(:list_id => '01234012340123401234fffff', :id => '1')

get '/lists/2/todos/1'
assert_equal 'Not Found', @response.body
assert_raises(ActionController::RoutingError){ list_todo_path(:list_id => '2', :id => '1') }
end

private
def with_test_routes
yield
Expand Down

0 comments on commit 9441eab

Please sign in to comment.