From 16b421d9bca432db05eb837bbd47ae95ba83420c Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 22 Jun 2010 17:26:35 -0300 Subject: [PATCH] Allow namespace accept options in routes --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 +++++--- actionpack/test/dispatch/routing_test.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c31f681..f54ff02 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -341,9 +341,11 @@ module ActionDispatch scope(controller.to_sym) { yield } end - def namespace(path) + def namespace(path, options = {}) path = path.to_s - scope(:path => path, :name_prefix => path, :module => path, :shallow_path => path, :shallow_prefix => path) { yield } + options = { :path => path, :name_prefix => path, :module => path, + :shallow_path => path, :shallow_prefix => path }.merge!(options) + scope(options) { yield } end def constraints(constraints = {}) @@ -684,7 +686,7 @@ module ActionDispatch end end - def namespace(path) + def namespace(path, options = {}) if resource_scope? nested { super } else diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 495255c..bb8958c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -242,6 +242,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + namespace :users, :path => 'usuarios' do + root :to => 'home#index' + end + controller :articles do scope '/articles', :name_prefix => 'article' do scope :path => '/:title', :title => /[a-z]+/, :as => :with_title do @@ -932,6 +936,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_namespace_with_options + with_test_routes do + get '/usuarios' + assert_equal '/usuarios', users_root_path + assert_equal 'users/home#index', @response.body + end + end + def test_articles_with_id with_test_routes do get '/articles/rails/1' -- 1.7.0