Skip to content
This repository
Browse code

Allow symbols for :path resource(s) option [#5306 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 771d2f918fc87bdd4f83e6666fd816e9f0dcedfb 1 parent 4329146
Andrew White authored August 20, 2010 josevalim committed August 20, 2010
4  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -473,7 +473,7 @@ class Resource #:nodoc:
473 473
 
474 474
           def initialize(entities, options = {})
475 475
             @name       = entities.to_s
476  
-            @path       = options.delete(:path) || @name
  476
+            @path       = (options.delete(:path) || @name).to_s
477 477
             @controller = (options.delete(:controller) || @name).to_s
478 478
             @as         = options.delete(:as)
479 479
             @options    = options
@@ -537,7 +537,7 @@ class SingletonResource < Resource #:nodoc:
537 537
 
538 538
           def initialize(entities, options)
539 539
             @name       = entities.to_s
540  
-            @path       = options.delete(:path) || @name
  540
+            @path       = (options.delete(:path) || @name).to_s
541 541
             @controller = (options.delete(:controller) || plural).to_s
542 542
             @as         = options.delete(:as)
543 543
             @options    = options
19  actionpack/test/dispatch/routing_test.rb
@@ -385,6 +385,9 @@ def self.matches?(request)
385 385
         end
386 386
       end
387 387
 
  388
+      resources :wiki_pages, :path => :pages
  389
+      resource :wiki_account, :path => :my_account
  390
+
388 391
       scope :only => :show do
389 392
         namespace :only do
390 393
           resources :sectors, :only => :index do
@@ -1984,6 +1987,22 @@ def test_resource_constraints_are_pushed_to_scope
1984 1987
     end
1985 1988
   end
1986 1989
 
  1990
+  def test_resources_path_can_be_a_symbol
  1991
+    with_test_routes do
  1992
+      get '/pages'
  1993
+      assert_equal 'wiki_pages#index', @response.body
  1994
+      assert_equal '/pages', wiki_pages_path
  1995
+
  1996
+      get '/pages/Ruby_on_Rails'
  1997
+      assert_equal 'wiki_pages#show', @response.body
  1998
+      assert_equal '/pages/Ruby_on_Rails', wiki_page_path(:id => 'Ruby_on_Rails')
  1999
+
  2000
+      get '/my_account'
  2001
+      assert_equal 'wiki_accounts#show', @response.body
  2002
+      assert_equal '/my_account', wiki_account_path
  2003
+    end
  2004
+  end
  2005
+
1987 2006
 private
1988 2007
   def with_test_routes
1989 2008
     yield

0 notes on commit 771d2f9

Please sign in to comment.
Something went wrong with that request. Please try again.