Skip to content

Commit

Permalink
Allow symbols for :path resource(s) option [#5306 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
pixeltrix authored and josevalim committed Aug 20, 2010
1 parent 20088f6 commit c6391e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -473,7 +473,7 @@ class Resource #:nodoc:

def initialize(entities, options = {})
@name = entities.to_s
@path = options.delete(:path) || @name
@path = (options.delete(:path) || @name).to_s
@controller = (options.delete(:controller) || @name).to_s
@as = options.delete(:as)
@options = options
Expand Down Expand Up @@ -537,7 +537,7 @@ class SingletonResource < Resource #:nodoc:

def initialize(entities, options)
@name = entities.to_s
@path = options.delete(:path) || @name
@path = (options.delete(:path) || @name).to_s
@controller = (options.delete(:controller) || plural).to_s
@as = options.delete(:as)
@options = options
Expand Down
19 changes: 19 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -385,6 +385,9 @@ def self.matches?(request)
end
end

resources :wiki_pages, :path => :pages
resource :wiki_account, :path => :my_account

scope :only => :show do
namespace :only do
resources :sectors, :only => :index do
Expand Down Expand Up @@ -1984,6 +1987,22 @@ def test_resource_constraints_are_pushed_to_scope
end
end

def test_resources_path_can_be_a_symbol
with_test_routes do
get '/pages'
assert_equal 'wiki_pages#index', @response.body
assert_equal '/pages', wiki_pages_path

get '/pages/Ruby_on_Rails'
assert_equal 'wiki_pages#show', @response.body
assert_equal '/pages/Ruby_on_Rails', wiki_page_path(:id => 'Ruby_on_Rails')

get '/my_account'
assert_equal 'wiki_accounts#show', @response.body
assert_equal '/my_account', wiki_account_path
end
end

private
def with_test_routes
yield
Expand Down

0 comments on commit c6391e6

Please sign in to comment.