Permalink
Browse files

Fixes namespaced routes [#3673 status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent d2c4a93 commit 36969c6ecd69fc285bf0267805152319a4b71ceb @jcxplorer jcxplorer committed with josevalim Jan 9, 2010
Showing with 13 additions and 5 deletions.
  1. +10 −2 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +3 −3 actionpack/test/dispatch/routing_test.rb
@@ -258,10 +258,17 @@ def scope(*args)
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 @@ def scope(*args)
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 @@ def controller(controller)
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 = {})
@@ -432,15 +432,15 @@ def test_articles_perma
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

0 comments on commit 36969c6

Please sign in to comment.