Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7713

Show
Ignore:
Timestamp:
10/01/07 06:44:07 (1 year ago)
Author:
nzkoz
Message:

Change the resource seperator from ; to / change the generated routes to use the new-style named routes. e.g. new_group_user_path(@group) instead of group_new_user_path(@group). [pixeltrix] Closes #8558

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1-2-stable/actionpack/CHANGELOG

    r7319 r7713  
    11*SVN* 
     2 
     3* Change the resource seperator from ; to / change the generated routes to use the new-style named routes.  e.g.  new_group_user_path(@group) instead of group_new_user_path(@group). [pixeltrix] 
     4 
     5 
    26 
    37* Integration tests: introduce methods for other HTTP methods.  #6353 [caboose] 
  • branches/1-2-stable/actionpack/lib/action_controller/base.rb

    r7600 r7713  
    293293    cattr_accessor :ignore_missing_templates 
    294294 
     295    # Controls the resource action separator 
     296    @@resource_action_separator = "/" 
     297    cattr_accessor :resource_action_separator 
     298 
    295299    # Holds the request object that's primarily used to get environment variables through access like 
    296300    # <tt>request.env["REQUEST_URI"]</tt>. 
  • branches/1-2-stable/actionpack/lib/action_controller/resources.rb

    r7600 r7713  
    33    class Resource #:nodoc: 
    44      attr_reader :collection_methods, :member_methods, :new_methods 
    5       attr_reader :path_prefix, :name_prefix 
     5      attr_reader :path_prefix, :new_name_prefix 
    66      attr_reader :plural, :singular 
    77      attr_reader :options 
     
    1010        @plural   = entities 
    1111        @singular = options[:singular] || plural.to_s.singularize 
    12          
     12 
    1313        @options = options 
    1414 
     
    1717        set_prefixes 
    1818      end 
    19        
     19 
    2020      def controller 
    2121        @controller ||= (options[:controller] || plural).to_s 
    2222      end 
    23        
     23 
    2424      def path 
    2525        @path ||= "#{path_prefix}/#{plural}" 
    2626      end 
    27        
     27 
    2828      def new_path 
    2929        @new_path ||= "#{path}/new" 
    3030      end 
    31        
     31 
    3232      def member_path 
    3333        @member_path ||= "#{path}/:id" 
    3434      end 
    35        
     35 
    3636      def nesting_path_prefix 
    3737        @nesting_path_prefix ||= "#{path}/:#{singular}_id" 
    3838      end 
    39        
     39 
     40      def deprecate_name_prefix? 
     41        @name_prefix.blank? && !@new_name_prefix.blank? 
     42      end 
     43 
     44      def name_prefix 
     45        deprecate_name_prefix? ? @new_name_prefix : @name_prefix 
     46      end 
     47 
     48      def old_name_prefix 
     49        @name_prefix 
     50      end 
     51 
     52      def nesting_name_prefix 
     53        "#{new_name_prefix}#{singular}_" 
     54      end 
     55 
     56      def action_separator 
     57        @action_separator ||= Base.resource_action_separator 
     58      end 
     59 
    4060      protected 
    4161        def arrange_actions 
     
    4464          @new_methods        = arrange_actions_by_methods(options.delete(:new)) 
    4565        end 
    46          
     66 
    4767        def add_default_actions 
    4868          add_default_action(member_methods, :get, :edit) 
     
    5373          @path_prefix = options.delete(:path_prefix) 
    5474          @name_prefix = options.delete(:name_prefix) 
     75          @new_name_prefix = options.delete(:new_name_prefix) 
    5576        end 
    5677 
     
    6182          end 
    6283        end 
    63          
     84 
    6485        def add_default_action(collection, method, action) 
    6586          (collection[method] ||= []).unshift(action) 
     
    179200    #   The comment resources work the same, but must now include a value for :article_id. 
    180201    #    
    181     #     comments_url(@article) 
    182     #     comment_url(@article, @comment) 
    183     # 
    184     #     comments_url(:article_id => @article) 
    185     #     comment_url(:article_id => @article, :id => @comment) 
     202    #     article_comments_url(@article) 
     203    #     article_comment_url(@article, @comment) 
     204    # 
     205    #     article_comments_url(:article_id => @article) 
     206    #     article_comment_url(:article_id => @article, :id => @comment) 
    186207    # 
    187208    # * <tt>:name_prefix</tt> -- define a prefix for all generated routes, usually ending in an underscore. 
     
    193214    # * <tt>:collection</tt> -- add named routes for other actions that operate on the collection. 
    194215    #   Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt> 
    195     #   or <tt>:any</tt> if the method does not matter.  These routes map to a URL like /messages;rss, with a route of rss_messages_url. 
     216    #   or <tt>:any</tt> if the method does not matter.  These routes map to a URL like /messages/rss, with a route of rss_messages_url. 
    196217    # * <tt>:member</tt> -- same as :collection, but for actions that operate on a specific member. 
    197218    # * <tt>:new</tt> -- same as :collection, but for actions that operate on the new resource action. 
     
    205226    #   
    206227    #   map.resources :messages, :collection => { :rss => :get } 
    207     #   # --> GET /messages;rss (maps to the #rss action) 
     228    #   # --> GET /messages/rss (maps to the #rss action) 
    208229    #   #     also adds a named route called "rss_messages" 
    209230    #  
    210231    #   map.resources :messages, :member => { :mark => :post } 
    211     #   # --> POST /messages/1;mark (maps to the #mark action) 
     232    #   # --> POST /messages/1/mark (maps to the #mark action) 
    212233    #   #     also adds a named route called "mark_message" 
    213234    #  
    214235    #   map.resources :messages, :new => { :preview => :post } 
    215     #   # --> POST /messages/new;preview (maps to the #preview action) 
     236    #   # --> POST /messages/new/preview (maps to the #preview action) 
    216237    #   #     also adds a named route called "preview_new_message" 
    217238    #  
    218239    #   map.resources :messages, :new => { :new => :any, :preview => :post } 
    219     #   # --> POST /messages/new;preview (maps to the #preview action) 
     240    #   # --> POST /messages/new/preview (maps to the #preview action) 
    220241    #   #     also adds a named route called "preview_new_message" 
    221242    #   # --> /messages/new can be invoked via any request method 
     
    236257    #  
    237258    # See map.resources for general conventions.  These are the main differences: 
    238     #   - a singular name is given to map.resource.  The default controller name is taken from the singular name. 
    239     #   - To specify a custom plural name, use the :plural option.  There is no :singular option 
    240     #   - No default index, new, or create routes are created for the singleton resource controller. 
     259    #   - A singular name is given to map.resource.  The default controller name is taken from the singular name. 
     260    #   - There is no <tt>:collection</tt> option as there is only the singleton resource. 
     261    #   - There is no <tt>:singular</tt> option as the singular name is passed to map.resource. 
     262    #   - No default index route is created for the singleton resource controller. 
    241263    #   - When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1') 
    242264    # 
     
    301323 
    302324          if block_given? 
    303             with_options(:path_prefix => resource.nesting_path_prefix, &block) 
     325            with_options(:path_prefix => resource.nesting_path_prefix, :new_name_prefix => resource.nesting_name_prefix, &block) 
    304326          end 
    305327        end 
     
    316338 
    317339          if block_given? 
    318             with_options(:path_prefix => resource.nesting_path_prefix, &block) 
     340            with_options(:path_prefix => resource.nesting_path_prefix, :new_name_prefix => resource.nesting_name_prefix, &block) 
    319341          end 
    320342        end 
     
    325347          actions.each do |action| 
    326348            action_options = action_options_for(action, resource, method) 
    327             map.named_route("#{resource.name_prefix}#{action}_#{resource.plural}", "#{resource.path};#{action}", action_options) 
    328             map.named_route("formatted_#{resource.name_prefix}#{action}_#{resource.plural}", "#{resource.path}.:format;#{action}", action_options) 
     349 
     350            unless resource.old_name_prefix.blank? 
     351              map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.old_name_prefix}#{action}_#{resource.plural}") 
     352              map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.old_name_prefix}#{action}_#{resource.plural}") 
     353            end 
     354 
     355            if resource.deprecate_name_prefix? 
     356              map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{action}_#{resource.plural}") 
     357              map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{action}_#{resource.plural}") 
     358            end 
     359 
     360            map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options) 
     361            map.connect("#{resource.path};#{action}", action_options) 
     362            map.connect("#{resource.path}.:format;#{action}", action_options) 
     363            map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options) 
    329364          end 
    330365        end 
     
    335370        map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options) 
    336371        map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", index_action_options) 
     372 
     373        if resource.deprecate_name_prefix? 
     374          map.deprecated_named_route("#{resource.name_prefix}#{resource.plural}", "#{resource.plural}") 
     375          map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.plural}") 
     376        end 
    337377 
    338378        create_action_options = action_options_for("create", resource) 
     
    352392            action_options = action_options_for(action, resource, method) 
    353393            if action == :new 
    354               map.named_route("#{resource.name_prefix}new_#{resource.singular}", resource.new_path, action_options) 
    355               map.named_route("formatted_#{resource.name_prefix}new_#{resource.singular}", "#{resource.new_path}.:format", action_options) 
     394 
     395              unless resource.old_name_prefix.blank? 
     396                map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}new_#{resource.singular}") 
     397                map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}new_#{resource.singular}") 
     398              end 
     399 
     400              if resource.deprecate_name_prefix? 
     401                map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "new_#{resource.singular}") 
     402                map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_new_#{resource.singular}") 
     403              end 
     404 
     405              map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options) 
     406              map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options) 
     407 
    356408            else 
    357               map.named_route("#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path};#{action}", action_options) 
    358               map.named_route("formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path}.:format;#{action}", action_options) 
     409 
     410              unless resource.old_name_prefix.blank? 
     411                map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}#{action}_new_#{resource.singular}") 
     412                map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}#{action}_new_#{resource.singular}") 
     413              end 
     414 
     415              if resource.deprecate_name_prefix? 
     416                map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{action}_new_#{resource.singular}") 
     417                map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_new_#{resource.singular}") 
     418              end 
     419 
     420              map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options) 
     421              map.connect("#{resource.new_path};#{action}", action_options) 
     422              map.connect("#{resource.new_path}.:format;#{action}", action_options) 
     423              map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options) 
     424 
    359425            end 
    360426          end 
     
    366432          actions.each do |action| 
    367433            action_options = action_options_for(action, resource, method) 
    368             map.named_route("#{resource.name_prefix}#{action}_#{resource.singular}", "#{resource.member_path};#{action}", action_options) 
    369             map.named_route("formatted_#{resource.name_prefix}#{action}_#{resource.singular}", "#{resource.member_path}.:format;#{action}",action_options) 
     434 
     435            unless resource.old_name_prefix.blank? 
     436              map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}#{action}_#{resource.singular}") 
     437              map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}#{action}_#{resource.singular}") 
     438            end 
     439 
     440            if resource.deprecate_name_prefix? 
     441              map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{action}_#{resource.singular}") 
     442              map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_#{resource.singular}") 
     443            end 
     444 
     445            map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options) 
     446            map.connect("#{resource.member_path};#{action}", action_options) 
     447            map.connect("#{resource.member_path}.:format;#{action}", action_options) 
     448            map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format", action_options) 
     449 
    370450          end 
    371451        end 
     
    374454        map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options) 
    375455        map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", show_action_options) 
     456 
     457        if resource.deprecate_name_prefix? 
     458          map.deprecated_named_route("#{resource.name_prefix}#{resource.singular}", "#{resource.singular}") 
     459          map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.singular}") 
     460        end 
    376461 
    377462        update_action_options = action_options_for("update", resource) 
  • branches/1-2-stable/actionpack/lib/action_controller/routing.rb

    r7600 r7713  
    990990          @set.add_named_route(name, path, options) 
    991991        end 
     992         
     993        def deprecated_named_route(name, deprecated_name, options = {}) 
     994          @set.add_deprecated_named_route(name, deprecated_name) 
     995        end 
    992996 
    993997        # Added deprecation notice for anyone who already added a named route called "root". 
     
    10201024          @routes = {} 
    10211025          @helpers = [] 
    1022            
     1026 
    10231027          @module ||= Module.new 
    10241028          @module.instance_methods.each do |selector| 
     
    10551059        def install(destinations = [ActionController::Base, ActionView::Base]) 
    10561060          Array(destinations).each { |dest| dest.send :include, @module } 
     1061        end 
     1062         
     1063        def define_deprecated_named_route_methods(name, deprecated_name) 
     1064 
     1065          [:url, :path].each do |kind| 
     1066            @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks 
     1067 
     1068              def #{url_helper_name(deprecated_name, kind)}(*args) 
     1069 
     1070                ActiveSupport::Deprecation.warn( 
     1071                  'The named route "#{url_helper_name(deprecated_name, kind)}" uses a format that has been deprecated. ' + 
     1072                  'You should use "#{url_helper_name(name, kind)}" instead.', caller 
     1073                ) 
     1074 
     1075                send :#{url_helper_name(name, kind)}, *args 
     1076 
     1077              end 
     1078 
     1079              def #{hash_access_name(deprecated_name, kind)}(*args) 
     1080 
     1081                ActiveSupport::Deprecation.warn( 
     1082                  'The named route "#{hash_access_name(deprecated_name, kind)}" uses a format that has been deprecated. ' + 
     1083                  'You should use "#{hash_access_name(name, kind)}" instead.', caller 
     1084                ) 
     1085 
     1086                send :#{hash_access_name(name, kind)}, *args 
     1087 
     1088              end 
     1089 
     1090            end_eval 
     1091          end 
     1092 
    10571093        end 
    10581094 
     
    11781214        named_routes[name] = add_route(path, options) 
    11791215      end 
     1216       
     1217      def add_deprecated_named_route(name, deprecated_name) 
     1218        named_routes.define_deprecated_named_route_methods(name, deprecated_name) 
     1219      end 
    11801220   
    11811221      def options_as_params(options) 
  • branches/1-2-stable/actionpack/test/controller/resources_test.rb

    r7600 r7713  
    1111class CommentsController < ResourcesController; end 
    1212 
    13 class AccountController <  ResourcesController; end 
    14 class AdminController   <  ResourcesController; end 
     13class AccountController  < ResourcesController; end 
     14class AdminController    < ResourcesController; end 
     15class ProductsController < ResourcesController; end 
    1516 
    1617class ResourcesTest < Test::Unit::TestCase 
     
    6465  end 
    6566 
    66   def test_multile_with_path_prefix 
     67  def test_multiple_with_path_prefix 
    6768    with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do 
    6869      assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 
     
    7071    end 
    7172  end 
    72    
     73 
    7374  def test_with_name_prefix 
    7475    with_restful_routing :messages, :name_prefix => 'post_' do 
     
    7980  def test_with_collection_action 
    8081    rss_options = {:action => 'rss'} 
    81     rss_path    = "/messages;rss" 
     82    rss_path    = "/messages/rss" 
    8283    actions = { 'a' => :put, 'b' => :post, 'c' => :delete } 
    8384 
     
    8788 
    8889        actions.each do |action, method| 
    89           assert_recognizes(options.merge(:action => action), :path => "/messages;#{action}", :method => method) 
     90          assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method) 
    9091        end 
    9192      end 
     
    9495        assert_named_route rss_path, :rss_messages_path, rss_options 
    9596        actions.keys.each do |action| 
    96           assert_named_route "/messages;#{action}", "#{action}_messages_path", :action => action 
     97          assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action 
    9798        end 
    9899      end 
     
    104105      with_restful_routing :messages, :member => { :mark => method } do 
    105106        mark_options = {:action => 'mark', :id => '1'} 
    106         mark_path    = "/messages/1;mark" 
     107        mark_path    = "/messages/1/mark" 
    107108        assert_restful_routes_for :messages do |options| 
    108109          assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) 
     
    121122        %w(mark unmark).each do |action| 
    122123          action_options = {:action => action, :id => '1'} 
    123           action_path    = "/messages/1;#{action}" 
     124          action_path    = "/messages/1/#{action}" 
    124125          assert_restful_routes_for :messages do |options| 
    125126            assert_recognizes(options.merge(action_options), :path => action_path, :method => method) 
     
    137138    with_restful_routing :messages, :new => { :preview => :post } do 
    138139      preview_options = {:action => 'preview'} 
    139       preview_path    = "/messages/new;preview" 
     140      preview_path    = "/messages/new/preview" 
    140141      assert_restful_routes_for :messages do |options| 
    141142        assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) 
     
    179180      assert_simply_restful_for :messages, 
    180181        :path_prefix => 'threads/1/', 
     182        :name_prefix => 'thread_', 
    181183        :options => { :thread_id => '1' } 
    182184      assert_simply_restful_for :comments, 
    183185        :path_prefix => 'threads/1/messages/2/', 
     186        :name_prefix => 'thread_message_', 
    184187        :options => { :thread_id => '1', :message_id => '2' } 
    185188    end 
     
    218221        end 
    219222      end 
    220        
     223 
    221224      assert_singleton_restful_for :admin 
    222       assert_singleton_restful_for :account, :path_prefix => 'admin/' 
     225      assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_' 
    223226    end 
    224227  end 
     
    228231      with_singleton_resources :account, :member => { :reset => method } do 
    229232        reset_options = {:action => 'reset'} 
    230         reset_path    = "/account;reset" 
     233        reset_path    = "/account/reset" 
    231234        assert_singleton_routes_for :account do |options| 
    232235          assert_recognizes(options.merge(reset_options), :path => reset_path, :method => method) 
     
    245248        %w(reset disable).each do |action| 
    246249          action_options = {:action => action} 
    247           action_path    = "/account;#{action}" 
     250          action_path    = "/account/#{action}" 
    248251          assert_singleton_routes_for :account do |options| 
    249252            assert_recognizes(options.merge(action_options), :path => action_path, :method => method) 
     
    265268        end 
    266269      end 
    267        
     270 
    268271      assert_singleton_restful_for :account 
    269       assert_simply_restful_for :messages, :path_prefix => 'account/' 
     272      assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_' 
    270273    end 
    271274  end 
     
    280283 
    281284      assert_singleton_restful_for :account, :path_prefix => '7/', :options => { :site_id => '7' } 
    282       assert_simply_restful_for :messages, :path_prefix => '7/account/', :options => { :site_id => '7' } 
    283     end 
    284   end 
    285    
     285      assert_simply_restful_for :messages, :path_prefix => '7/account/', :name_prefix => 'account_', :options => { :site_id => '7' } 
     286    end 
     287  end 
     288 
    286289  def test_should_nest_singleton_resource_in_resources 
    287290    with_routing do |set| 
     
    291294        end 
    292295      end 
    293        
     296 
    294297      assert_simply_restful_for :threads 
    295       assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :options => { :thread_id => '5' } 
     298      assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' } 
    296299    end 
    297300  end 
     
    313316  end 
    314317 
     318  def test_resource_action_separator 
     319    with_routing do |set| 
     320      set.draw do |map| 
     321        map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 
     322        map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 
     323      end 
     324 
     325      action_separator = ActionController::Base.resource_action_separator 
     326 
     327      assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 
     328      assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {} 
     329      assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} 
     330      assert_named_route "/threads/1/messages/new#{action_separator}preview", "preview_new_thread_message_path", {} 
     331      assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 
     332      assert_named_route "/admin/account#{action_separator}login", "login_admin_account_path", {} 
     333      assert_named_route "/admin/account/new", "new_admin_account_path", {} 
     334      assert_named_route "/admin/account/new#{action_separator}preview", "preview_new_admin_account_path", {} 
     335    end 
     336  end 
     337 
     338  def test_new_style_named_routes_for_resource 
     339    with_routing do |set| 
     340      set.draw do |map| 
     341        map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 
     342      end 
     343      assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 
     344      assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {} 
     345      assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} 
     346      assert_named_route "/threads/1/messages/new/preview", "preview_new_thread_message_path", {} 
     347    end 
     348  end 
     349 
     350  def test_new_style_named_routes_for_singleton_resource 
     351    with_routing do |set| 
     352      set.draw do |map| 
     353        map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 
     354      end 
     355      assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 
     356      assert_named_route "/admin/account/login", "login_admin_account_path", {} 
     357      assert_named_route "/admin/account/new", "new_admin_account_path", {} 
     358      assert_named_route "/admin/account/new/preview", "preview_new_admin_account_path", {} 
     359    end 
     360  end 
     361 
     362  def test_should_add_deprecated_named_routes_for_resource 
     363    with_routing do |set| 
     364      set.draw do |map| 
     365        map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 
     366      end 
     367      assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 
     368      assert_deprecated do 
     369        assert_named_route "/threads/1/messages/search", "thread_search_messages_path", {} 
     370        assert_named_route "/threads/1/messages/new", "thread_new_message_path", {} 
     371        assert_named_route "/threads/1/messages/new/preview", "thread_preview_new_message_path", {} 
     372      end 
     373    end 
     374  end 
     375 
     376  def test_should_add_deprecated_named_routes_for_singleton_resource 
     377    with_routing do |set| 
     378      set.draw do |map| 
     379        map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 
     380      end 
     381      assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 
     382      assert_deprecated do 
     383        assert_named_route "/admin/account/login", "admin_login_account_path", {} 
     384        assert_named_route "/admin/account/new", "admin_new_account_path", {} 
     385        assert_named_route "/admin/account/new/preview", "admin_preview_new_account_path", {} 
     386      end 
     387    end 
     388  end 
     389 
     390  def test_should_add_deprecated_named_routes_for_nested_resources 
     391    with_routing do |set| 
     392      set.draw do |map| 
     393        map.resources :threads do |map| 
     394          map.resources :messages do |map| 
     395            map.resources :comments 
     396          end 
     397        end 
     398      end 
     399 
     400      assert_simply_restful_for :threads 
     401      assert_simply_restful_for :messages, 
     402        :path_prefix => 'threads/1/', 
     403        :name_prefix => 'thread_', 
     404        :options => { :thread_id => '1' } 
     405      assert_simply_restful_for :comments, 
     406        :path_prefix => 'threads/1/messages/2/', 
     407        :name_prefix => 'thread_message_', 
     408        :options => { :thread_id => '1', :message_id => '2' } 
     409 
     410      assert_deprecated do 
     411        assert_named_route "/threads/1/messages", "messages_path", {} 
     412        assert_named_route "/threads/1/messages/1", "message_path", {:thread_id => '1', :id => '1'} 
     413        assert_named_route "/threads/1/messages/new", "new_message_path", {:thread_id => '1'} 
     414        assert_named_route "/threads/1/messages/1/edit", "edit_message_path", {:thread_id => '1', :id => '1'} 
     415      end 
     416    end 
     417  end 
     418 
     419  def test_should_add_deprecated_named_routes_for_nested_singleton_resources 
     420    with_routing do |set| 
     421      set.draw do |map| 
     422        map.resource :admin do |admin| 
     423          admin.resource :account 
     424        end 
     425      end 
     426 
     427      assert_singleton_restful_for :admin 
     428      assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_' 
     429 
     430      assert_deprecated do 
     431        assert_named_route "/admin/account", "account_path", {} 
     432        assert_named_route "/admin/account/new", "new_account_path", {} 
     433        assert_named_route "/admin/account/edit", "edit_account_path", {} 
     434      end 
     435    end 
     436  end 
     437 
     438  def test_should_add_deprecated_named_routes_for_nested_resources_in_singleton_resource 
     439    with_routing do |set| 
     440      set.draw do |map| 
     441        map.resource :account do |account| 
     442          account.resources :messages 
     443        end 
     444      end 
     445 
     446      assert_singleton_restful_for :account 
     447      assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_' 
     448 
     449      assert_deprecated do 
     450        assert_named_route "/account/messages", "messages_path", {} 
     451        assert_named_route "/account/messages/1", "message_path", {:id => '1'} 
     452        assert_named_route "/account/messages/new", "new_message_path", {} 
     453        assert_named_route "/account/messages/1/edit", "edit_message_path", {:id => '1'} 
     454      end 
     455    end 
     456  end 
     457 
     458  def test_should_add_deprecated_named_routes_for_nested_singleton_resource_in_resources 
     459    with_routing do |set| 
     460      set.draw do |map| 
     461        map.resources :threads do |thread| 
     462          thread.resource :admin 
     463        end 
     464      end 
     465 
     466      assert_simply_restful_for :threads 
     467      assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' } 
     468 
     469      assert_deprecated do 
     470        assert_named_route "/threads/5/admin", "admin_path", {} 
     471        assert_named_route "/threads/5/admin/new", "new_admin_path", {} 
     472        assert_named_route "/threads/5/admin/edit", "edit_admin_path", {} 
     473      end 
     474    end 
     475  end 
     476 
     477  def test_should_add_deprecated_formatted_routes 
     478    with_routing do |set| 
     479      set.draw do |map| 
     480        map.resources :products, :collection => { :specials => :get }, :member => { :thumbnail => :get } 
     481        map.resource :account, :member => { :icon => :get } 
     482      end 
     483      assert_restful_routes_for :products do |options| 
     484        assert_recognizes options.merge({ :action => 'specials', :format => 'xml' }), :path => '/products.xml;specials', :method => :get 
     485        assert_recognizes options.merge({ :action => 'thumbnail', :format => 'jpg', :id => '1' }), :path => '/products/1.jpg;thumbnail', :method => :get 
     486      end 
     487      assert_singleton_restful_for :account do |options| 
     488        assert_recognizes options.merge({ :action => 'icon', :format => 'jpg' }), :path => '/account.jpg;icon', :method => :get 
     489      end 
     490    end 
     491  end 
     492 
    315493  protected 
    316494    def with_restful_routing(*args) 
     
    320498      end 
    321499    end 
    322      
     500 
    323501    def with_singleton_resources(*args) 
    324502      with_routing do |set| 
     
    345523      member_path                = "#{collection_path}/1" 
    346524      new_path                   = "#{collection_path}/new" 
    347       edit_member_path           = "#{member_path};edit" 
    348       formatted_edit_member_path = "#{member_path}.xml;edit
     525      edit_member_path           = "#{member_path}/edit" 
     526      formatted_edit_member_path = "#{member_path}/edit.xml
    349527 
    350528      with_options(options[:options]) do |controller| 
     
    396574 
    397575      assert_named_route "#{full_prefix}",            "#{name_prefix}#{controller_name}_path",              options[:options] 
    398       assert_named_route "#{full_prefix}/new",        "#{name_prefix}new_#{singular_name}_path",            options[:options] 
     576      assert_named_route "#{full_prefix}/new",        "new_#{name_prefix}#{singular_name}_path",            options[:options] 
    399577      assert_named_route "#{full_prefix}/1",          "#{name_prefix}#{singular_name}_path",                options[:options].merge(:id => '1') 
    400       assert_named_route "#{full_prefix}/1;edit",     "#{name_prefix}edit_#{singular_name}_path",           options[:options].merge(:id => '1') 
     578      assert_named_route "#{full_prefix}/1/edit",     "edit_#{name_prefix}#{singular_name}_path",           options[:options].merge(:id => '1') 
    401579      assert_named_route "#{full_prefix}.xml",        "formatted_#{name_prefix}#{controller_name}_path",    options[:options].merge(            :format => 'xml') 
    402       assert_named_route "#{full_prefix}/new.xml",    "formatted_#{name_prefix}new_#{singular_name}_path",  options[:options].merge(            :format => 'xml') 
     580      assert_named_route "#{full_prefix}/new.xml",    "formatted_new_#{name_prefix}#{singular_name}_path",  options[:options].merge(            :format => 'xml') 
    403581      assert_named_route "#{full_prefix}/1.xml",      "formatted_#{name_prefix}#{singular_name}_path",      options[:options].merge(:id => '1', :format => 'xml') 
    404       assert_named_route "#{full_prefix}/1.xml;edit", "formatted_#{name_prefix}edit_#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') 
     582      assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') 
    405583      yield options[:options] if block_given? 
    406584    end 
     
    411589      full_path           = "/#{options[:path_prefix]}#{singleton_name}" 
    412590      new_path            = "#{full_path}/new" 
    413       edit_path           = "#{full_path};edit" 
    414       formatted_edit_path = "#{full_path}.xml;edit
     591      edit_path           = "#{full_path}/edit" 
     592      formatted_edit_path = "#{full_path}/edit.xml
    415593 
    416594      with_options options[:options] do |controller| 
     
    449627 
    450628      full_path = "/#{options[:path_prefix]}#{singleton_name}" 
    451  
    452       assert_named_route "#{full_path}",          "#{singleton_name}_path",                options[:options] 
    453       assert_named_route "#{full_path}/new",      "new_#{singleton_name}_path",            options[:options] 
    454       assert_named_route "#{full_path};edit",     "edit_#{singleton_name}_path",           options[:options] 
    455       assert_named_route "#{full_path}.xml",      "formatted_#{singleton_name}_path",      options[:options].merge(:format => 'xml') 
    456       assert_named_route "#{full_path}/new.xml",  "formatted_new_#{singleton_name}_path",  options[:options].merge(:format => 'xml') 
    457       assert_named_route "#{full_path}.xml;edit", "formatted_edit_#{singleton_name}_path", options[:options].merge(:format => 'xml') 
     629      full_name = "#{options[:name_prefix]}#{singleton_name}" 
     630 
     631      assert_named_route "#{full_path}",          "#{full_name}_path",                options[:options] 
     632      assert_named_route "#{full_path}/new",      "new_#{full_name}_path",            options[:options] 
     633      assert_named_route "#{full_path}/edit",     "edit_#{full_name}_path",           options[:options] 
     634      assert_named_route "#{full_path}.xml",      "formatted_#{full_name}_path",      options[:options].merge(:format => 'xml') 
     635      assert_named_route "#{full_path}/new.xml",  "formatted_new_#{full_name}_path",  options[:options].merge(:format => 'xml') 
     636      assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{full_name}_path", options[:options].merge(:format => 'xml') 
    458637    end 
    459638