diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 9 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 26 |
2 files changed, 31 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e283cf0403..48fb7edd67 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -328,13 +328,14 @@ module ActionDispatch def initialize(entities, options = {}) entities = entities.to_s + @options = options @plural = entities.pluralize @singular = entities.singularize end def name - plural + @options[:as] || plural end def controller @@ -360,7 +361,7 @@ module ActionDispatch end def name - singular + @options[:as] || singular end end @@ -373,7 +374,7 @@ module ActionDispatch return self end - resource = SingletonResource.new(resources.pop) + resource = SingletonResource.new(resources.pop, options) if @scope[:scope_level] == :resources nested do @@ -407,7 +408,7 @@ module ActionDispatch return self end - resource = Resource.new(resources.pop) + resource = Resource.new(resources.pop, options) if @scope[:scope_level] == :resources nested do diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 61cd2e3007..374d2b6b33 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -109,6 +109,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + namespace :forum do + resources :products, :as => '' do + resources :questions + end + end + controller :articles do scope '/articles', :name_prefix => 'article' do scope :path => '/:title', :title => /[a-z]+/, :as => :with_title do @@ -441,6 +447,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_forum_products + with_test_routes do + get '/forum' + assert_equal 'forum/products#index', @response.body + assert_equal '/forum', forum_products_path + + get '/forum/basecamp' + assert_equal 'forum/products#show', @response.body + assert_equal '/forum/basecamp', forum_product_path(:id => 'basecamp') + + get '/forum/basecamp/questions' + assert_equal 'forum/questions#index', @response.body + assert_equal '/forum/basecamp/questions', forum_product_questions_path(:product_id => 'basecamp') + + get '/forum/basecamp/questions/1' + assert_equal 'forum/questions#show', @response.body + assert_equal '/forum/basecamp/questions/1', forum_product_question_path(:product_id => 'basecamp', :id => 1) + end + end + def test_articles_perma with_test_routes do get '/articles/2009/08/18/rails-3' |