diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 12 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 6 |
2 files changed, 13 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3e577c7f99..00659c8bd4 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -258,10 +258,17 @@ module ActionDispatch else name_prefix_set = false end + + if namespace = options.delete(:namespace) + namespace_set = true + namespace, @scope[:namespace] = @scope[:namespace], namespace + else + namespace_set = false + end if controller = options.delete(:controller) controller_set = true - controller, @scope[:controller] = @scope[:controller], controller + controller, @scope[:controller] = @scope[:controller], @scope[:namespace] ? "#{@scope[:namespace]}/#{controller}" : controller else controller_set = false end @@ -281,6 +288,7 @@ module ActionDispatch ensure @scope[:path] = path if path_set @scope[:name_prefix] = name_prefix if name_prefix_set + @scope[:namespace] = namespace if namespace_set @scope[:controller] = controller if controller_set @scope[:options] = options @scope[:blocks] = blocks @@ -292,7 +300,7 @@ module ActionDispatch end def namespace(path) - scope("/#{path}", :name_prefix => path.to_s) { yield } + scope("/#{path}", :name_prefix => path.to_s, :namespace => path.to_s) { yield } end def constraints(constraints = {}) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 32e2717789..952cdb1098 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -432,15 +432,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_account_namespace with_test_routes do get '/account/subscription' - assert_equal 'subscriptions#show', @response.body + assert_equal 'account/subscriptions#show', @response.body assert_equal '/account/subscription', account_subscription_path get '/account/credit' - assert_equal 'credits#show', @response.body + assert_equal 'account/credits#show', @response.body assert_equal '/account/credit', account_credit_path get '/account/credit_card' - assert_equal 'credit_cards#show', @response.body + assert_equal 'account/credit_cards#show', @response.body assert_equal '/account/credit_card', account_credit_card_path end end |