Ensure nested namespaces work as expected.

This commit is contained in:
José Valim
2010-01-10 18:42:45 +01:00
parent 36969c6ecd
commit 8d72ba51ba
2 changed files with 16 additions and 7 deletions

View File

@@ -77,7 +77,6 @@ module ActionDispatch
path
end
def app
Constraints.new(
to.respond_to?(:call) ? to : Routing::RouteSet::Dispatcher.new(:defaults => defaults),
@@ -123,7 +122,6 @@ module ActionDispatch
end
end
def blocks
if @options[:constraints].present? && !@options[:constraints].is_a?(Hash)
block = @options[:constraints]
@@ -258,17 +256,17 @@ module ActionDispatch
else
name_prefix_set = false
end
if namespace = options.delete(:namespace)
namespace_set = true
namespace, @scope[:namespace] = @scope[:namespace], namespace
namespace, @scope[:namespace] = @scope[:namespace], (@scope[:namespace] ? "#{@scope[:namespace]}/#{namespace}" : namespace)
else
namespace_set = false
end
if controller = options.delete(:controller)
controller_set = true
controller, @scope[:controller] = @scope[:controller], @scope[:namespace] ? "#{@scope[:namespace]}/#{controller}" : controller
controller, @scope[:controller] = @scope[:controller], (@scope[:namespace] ? "#{@scope[:namespace]}/#{controller}" : controller)
else
controller_set = false
end
@@ -277,13 +275,12 @@ module ActionDispatch
unless constraints.is_a?(Hash)
block, constraints = constraints, {}
end
constraints, @scope[:constraints] = @scope[:constraints], (@scope[:constraints] || {}).merge(constraints)
blocks, @scope[:blocks] = @scope[:blocks], (@scope[:blocks] || []) + [block]
options, @scope[:options] = @scope[:options], (@scope[:options] || {}).merge(options)
yield
self
ensure
@scope[:path] = path if path_set

View File

@@ -99,6 +99,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
namespace :account do
resource :subscription, :credit, :credit_card
namespace :admin do
resource :subscription
end
end
controller :articles do
@@ -445,6 +449,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
def test_nested_namespace
with_test_routes do
get '/account/admin/subscription'
assert_equal 'account/admin/subscriptions#show', @response.body
assert_equal '/account/admin/subscription', account_admin_subscription_path
end
end
def test_articles_with_id
with_test_routes do
get '/articles/rails/1'