Changeset 7713
- Timestamp:
- 10/01/07 06:44:07 (1 year ago)
- Files:
-
- branches/1-2-stable/actionpack/CHANGELOG (modified) (1 diff)
- branches/1-2-stable/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- branches/1-2-stable/actionpack/lib/action_controller/resources.rb (modified) (17 diffs)
- branches/1-2-stable/actionpack/lib/action_controller/routing.rb (modified) (4 diffs)
- branches/1-2-stable/actionpack/test/controller/resources_test.rb (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1-2-stable/actionpack/CHANGELOG
r7319 r7713 1 1 *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 2 6 3 7 * Integration tests: introduce methods for other HTTP methods. #6353 [caboose] branches/1-2-stable/actionpack/lib/action_controller/base.rb
r7600 r7713 293 293 cattr_accessor :ignore_missing_templates 294 294 295 # Controls the resource action separator 296 @@resource_action_separator = "/" 297 cattr_accessor :resource_action_separator 298 295 299 # Holds the request object that's primarily used to get environment variables through access like 296 300 # <tt>request.env["REQUEST_URI"]</tt>. branches/1-2-stable/actionpack/lib/action_controller/resources.rb
r7600 r7713 3 3 class Resource #:nodoc: 4 4 attr_reader :collection_methods, :member_methods, :new_methods 5 attr_reader :path_prefix, :n ame_prefix5 attr_reader :path_prefix, :new_name_prefix 6 6 attr_reader :plural, :singular 7 7 attr_reader :options … … 10 10 @plural = entities 11 11 @singular = options[:singular] || plural.to_s.singularize 12 12 13 13 @options = options 14 14 … … 17 17 set_prefixes 18 18 end 19 19 20 20 def controller 21 21 @controller ||= (options[:controller] || plural).to_s 22 22 end 23 23 24 24 def path 25 25 @path ||= "#{path_prefix}/#{plural}" 26 26 end 27 27 28 28 def new_path 29 29 @new_path ||= "#{path}/new" 30 30 end 31 31 32 32 def member_path 33 33 @member_path ||= "#{path}/:id" 34 34 end 35 35 36 36 def nesting_path_prefix 37 37 @nesting_path_prefix ||= "#{path}/:#{singular}_id" 38 38 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 40 60 protected 41 61 def arrange_actions … … 44 64 @new_methods = arrange_actions_by_methods(options.delete(:new)) 45 65 end 46 66 47 67 def add_default_actions 48 68 add_default_action(member_methods, :get, :edit) … … 53 73 @path_prefix = options.delete(:path_prefix) 54 74 @name_prefix = options.delete(:name_prefix) 75 @new_name_prefix = options.delete(:new_name_prefix) 55 76 end 56 77 … … 61 82 end 62 83 end 63 84 64 85 def add_default_action(collection, method, action) 65 86 (collection[method] ||= []).unshift(action) … … 179 200 # The comment resources work the same, but must now include a value for :article_id. 180 201 # 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) 186 207 # 187 208 # * <tt>:name_prefix</tt> -- define a prefix for all generated routes, usually ending in an underscore. … … 193 214 # * <tt>:collection</tt> -- add named routes for other actions that operate on the collection. 194 215 # 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. 196 217 # * <tt>:member</tt> -- same as :collection, but for actions that operate on a specific member. 197 218 # * <tt>:new</tt> -- same as :collection, but for actions that operate on the new resource action. … … 205 226 # 206 227 # map.resources :messages, :collection => { :rss => :get } 207 # # --> GET /messages ;rss (maps to the #rss action)228 # # --> GET /messages/rss (maps to the #rss action) 208 229 # # also adds a named route called "rss_messages" 209 230 # 210 231 # 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) 212 233 # # also adds a named route called "mark_message" 213 234 # 214 235 # 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) 216 237 # # also adds a named route called "preview_new_message" 217 238 # 218 239 # 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) 220 241 # # also adds a named route called "preview_new_message" 221 242 # # --> /messages/new can be invoked via any request method … … 236 257 # 237 258 # 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. 241 263 # - When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1') 242 264 # … … 301 323 302 324 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) 304 326 end 305 327 end … … 316 338 317 339 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) 319 341 end 320 342 end … … 325 347 actions.each do |action| 326 348 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) 329 364 end 330 365 end … … 335 370 map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options) 336 371 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 337 377 338 378 create_action_options = action_options_for("create", resource) … … 352 392 action_options = action_options_for(action, resource, method) 353 393 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 356 408 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 359 425 end 360 426 end … … 366 432 actions.each do |action| 367 433 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 370 450 end 371 451 end … … 374 454 map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options) 375 455 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 376 461 377 462 update_action_options = action_options_for("update", resource) branches/1-2-stable/actionpack/lib/action_controller/routing.rb
r7600 r7713 990 990 @set.add_named_route(name, path, options) 991 991 end 992 993 def deprecated_named_route(name, deprecated_name, options = {}) 994 @set.add_deprecated_named_route(name, deprecated_name) 995 end 992 996 993 997 # Added deprecation notice for anyone who already added a named route called "root". … … 1020 1024 @routes = {} 1021 1025 @helpers = [] 1022 1026 1023 1027 @module ||= Module.new 1024 1028 @module.instance_methods.each do |selector| … … 1055 1059 def install(destinations = [ActionController::Base, ActionView::Base]) 1056 1060 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 1057 1093 end 1058 1094 … … 1178 1214 named_routes[name] = add_route(path, options) 1179 1215 end 1216 1217 def add_deprecated_named_route(name, deprecated_name) 1218 named_routes.define_deprecated_named_route_methods(name, deprecated_name) 1219 end 1180 1220 1181 1221 def options_as_params(options) branches/1-2-stable/actionpack/test/controller/resources_test.rb
r7600 r7713 11 11 class CommentsController < ResourcesController; end 12 12 13 class AccountController < ResourcesController; end 14 class AdminController < ResourcesController; end 13 class AccountController < ResourcesController; end 14 class AdminController < ResourcesController; end 15 class ProductsController < ResourcesController; end 15 16 16 17 class ResourcesTest < Test::Unit::TestCase … … 64 65 end 65 66 66 def test_multi le_with_path_prefix67 def test_multiple_with_path_prefix 67 68 with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do 68 69 assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } … … 70 71 end 71 72 end 72 73 73 74 def test_with_name_prefix 74 75 with_restful_routing :messages, :name_prefix => 'post_' do … … 79 80 def test_with_collection_action 80 81 rss_options = {:action => 'rss'} 81 rss_path = "/messages ;rss"82 rss_path = "/messages/rss" 82 83 actions = { 'a' => :put, 'b' => :post, 'c' => :delete } 83 84 … … 87 88 88 89 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) 90 91 end 91 92 end … … 94 95 assert_named_route rss_path, :rss_messages_path, rss_options 95 96 actions.keys.each do |action| 96 assert_named_route "/messages ;#{action}", "#{action}_messages_path", :action => action97 assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action 97 98 end 98 99 end … … 104 105 with_restful_routing :messages, :member => { :mark => method } do 105 106 mark_options = {:action => 'mark', :id => '1'} 106 mark_path = "/messages/1 ;mark"107 mark_path = "/messages/1/mark" 107 108 assert_restful_routes_for :messages do |options| 108 109 assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) … … 121 122 %w(mark unmark).each do |action| 122 123 action_options = {:action => action, :id => '1'} 123 action_path = "/messages/1 ;#{action}"124 action_path = "/messages/1/#{action}" 124 125 assert_restful_routes_for :messages do |options| 125 126 assert_recognizes(options.merge(action_options), :path => action_path, :method => method) … … 137 138 with_restful_routing :messages, :new => { :preview => :post } do 138 139 preview_options = {:action => 'preview'} 139 preview_path = "/messages/new ;preview"140 preview_path = "/messages/new/preview" 140 141 assert_restful_routes_for :messages do |options| 141 142 assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) … … 179 180 assert_simply_restful_for :messages, 180 181 :path_prefix => 'threads/1/', 182 :name_prefix => 'thread_', 181 183 :options => { :thread_id => '1' } 182 184 assert_simply_restful_for :comments, 183 185 :path_prefix => 'threads/1/messages/2/', 186 :name_prefix => 'thread_message_', 184 187 :options => { :thread_id => '1', :message_id => '2' } 185 188 end … … 218 221 end 219 222 end 220 223 221 224 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_' 223 226 end 224 227 end … … 228 231 with_singleton_resources :account, :member => { :reset => method } do 229 232 reset_options = {:action => 'reset'} 230 reset_path = "/account ;reset"233 reset_path = "/account/reset" 231 234 assert_singleton_routes_for :account do |options| 232 235 assert_recognizes(options.merge(reset_options), :path => reset_path, :method => method) … … 245 248 %w(reset disable).each do |action| 246 249 action_options = {:action => action} 247 action_path = "/account ;#{action}"250 action_path = "/account/#{action}" 248 251 assert_singleton_routes_for :account do |options| 249 252 assert_recognizes(options.merge(action_options), :path => action_path, :method => method) … … 265 268 end 266 269 end 267 270 268 271 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_' 270 273 end 271 274 end … … 280 283 281 284 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 286 289 def test_should_nest_singleton_resource_in_resources 287 290 with_routing do |set| … … 291 294 end 292 295 end 293 296 294 297 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' } 296 299 end 297 300 end … … 313 316 end 314 317 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 315 493 protected 316 494 def with_restful_routing(*args) … … 320 498 end 321 499 end 322 500 323 501 def with_singleton_resources(*args) 324 502 with_routing do |set| … … 345 523 member_path = "#{collection_path}/1" 346 524 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" 349 527 350 528 with_options(options[:options]) do |controller| … … 396 574 397 575 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] 399 577 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') 401 579 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') 403 581 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') 405 583 yield options[:options] if block_given? 406 584 end … … 411 589 full_path = "/#{options[:path_prefix]}#{singleton_name}" 412 590 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" 415 593 416 594 with_options options[:options] do |controller| … … 449 627 450 628 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') 458 637 end 459 638