Changeset 7600
- Timestamp:
- 09/23/07 22:03:09 (1 year ago)
- Files:
-
- branches/1-2-stable/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- branches/1-2-stable/actionpack/lib/action_controller/resources.rb (modified) (4 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) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1-2-stable/actionpack/lib/action_controller/base.rb
r7414 r7600 293 293 cattr_accessor :ignore_missing_templates 294 294 295 # Controls the resource action separator296 @@resource_action_separator = ";"297 cattr_accessor :resource_action_separator298 299 295 # Holds the request object that's primarily used to get environment variables through access like 300 296 # <tt>request.env["REQUEST_URI"]</tt>. branches/1-2-stable/actionpack/lib/action_controller/resources.rb
r7414 r7600 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 40 def action_separator 41 @action_separator ||= Base.resource_action_separator 42 end 43 39 44 40 protected 45 41 def arrange_actions … … 329 325 actions.each do |action| 330 326 action_options = action_options_for(action, resource, method) 331 332 unless resource.name_prefix.blank? 333 map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.name_prefix}#{action}_#{resource.plural}") 334 map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.name_prefix}#{action}_#{resource.plural}") 335 end 336 337 map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options) 338 map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options) 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) 339 329 end 340 330 end … … 362 352 action_options = action_options_for(action, resource, method) 363 353 if action == :new 364 365 unless resource.name_prefix.blank? 366 map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}new_#{resource.singular}") 367 map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}new_#{resource.singular}") 368 end 369 370 map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options) 371 map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options) 372 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) 373 356 else 374 375 unless resource.name_prefix.blank? 376 map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}#{action}_new_#{resource.singular}") 377 map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}") 378 end 379 380 map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options) 381 map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options) 382 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) 383 359 end 384 360 end … … 390 366 actions.each do |action| 391 367 action_options = action_options_for(action, resource, method) 392 393 unless resource.name_prefix.blank? 394 map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}#{action}_#{resource.singular}") 395 map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}#{action}_#{resource.singular}") 396 end 397 398 map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options) 399 map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format", action_options) 400 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) 401 370 end 402 371 end branches/1-2-stable/actionpack/lib/action_controller/routing.rb
r7414 r7600 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 end996 992 997 993 # Added deprecation notice for anyone who already added a named route called "root". … … 1024 1020 @routes = {} 1025 1021 @helpers = [] 1026 1022 1027 1023 @module ||= Module.new 1028 1024 @module.instance_methods.each do |selector| … … 1059 1055 def install(destinations = [ActionController::Base, ActionView::Base]) 1060 1056 Array(destinations).each { |dest| dest.send :include, @module } 1061 end1062 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 leaks1067 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.', caller1073 )1074 1075 send :#{url_helper_name(name, kind)}, *args1076 1077 end1078 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.', caller1084 )1085 1086 send :#{hash_access_name(name, kind)}, *args1087 1088 end1089 1090 end_eval1091 end1092 1093 1057 end 1094 1058 … … 1214 1178 named_routes[name] = add_route(path, options) 1215 1179 end 1216 1217 def add_deprecated_named_route(name, deprecated_name)1218 named_routes.define_deprecated_named_route_methods(name, deprecated_name)1219 end1220 1180 1221 1181 def options_as_params(options) branches/1-2-stable/actionpack/test/controller/resources_test.rb
r7414 r7600 64 64 end 65 65 66 def test_multi ple_with_path_prefix66 def test_multile_with_path_prefix 67 67 with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do 68 68 assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } … … 313 313 end 314 314 315 def test_resource_action_separator316 with_routing do |set|317 set.draw do |map|318 map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'319 map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'320 end321 322 action_separator = ActionController::Base.resource_action_separator323 324 assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }325 assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {}326 assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}327 assert_named_route "/threads/1/messages/new#{action_separator}preview", "preview_new_thread_message_path", {}328 assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'329 assert_named_route "/admin/account#{action_separator}login", "login_admin_account_path", {}330 assert_named_route "/admin/account/new", "new_admin_account_path", {}331 assert_named_route "/admin/account/new#{action_separator}preview", "preview_new_admin_account_path", {}332 end333 end334 335 def test_new_style_named_routes_for_resource336 with_routing do |set|337 set.draw do |map|338 map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'339 end340 assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }341 assert_named_route "/threads/1/messages;search", "search_thread_messages_path", {}342 assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}343 assert_named_route "/threads/1/messages/new;preview", "preview_new_thread_message_path", {}344 end345 end346 347 def test_new_style_named_routes_for_singleton_resource348 with_routing do |set|349 set.draw do |map|350 map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'351 end352 assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'353 assert_named_route "/admin/account;login", "login_admin_account_path", {}354 assert_named_route "/admin/account/new", "new_admin_account_path", {}355 assert_named_route "/admin/account/new;preview", "preview_new_admin_account_path", {}356 end357 end358 359 def test_should_add_deprecated_named_routes_for_resource360 with_routing do |set|361 set.draw do |map|362 map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'363 end364 assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }365 assert_deprecated do366 assert_named_route "/threads/1/messages;search", "thread_search_messages_path", {}367 assert_named_route "/threads/1/messages/new", "thread_new_message_path", {}368 assert_named_route "/threads/1/messages/new;preview", "thread_preview_new_message_path", {}369 end370 end371 end372 373 def test_should_add_deprecated_named_routes_for_singleton_resource374 with_routing do |set|375 set.draw do |map|376 map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'377 end378 assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/'379 assert_deprecated do380 assert_named_route "/admin/account;login", "admin_login_account_path", {}381 assert_named_route "/admin/account/new", "admin_new_account_path", {}382 assert_named_route "/admin/account/new;preview", "admin_preview_new_account_path", {}383 end384 end385 end386 387 315 protected 388 316 def with_restful_routing(*args) … … 418 346 new_path = "#{collection_path}/new" 419 347 edit_member_path = "#{member_path};edit" 420 formatted_edit_member_path = "#{member_path} ;edit.xml"348 formatted_edit_member_path = "#{member_path}.xml;edit" 421 349 422 350 with_options(options[:options]) do |controller| … … 468 396 469 397 assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options] 470 assert_named_route "#{full_prefix}/new", " new_#{name_prefix}#{singular_name}_path", options[:options]398 assert_named_route "#{full_prefix}/new", "#{name_prefix}new_#{singular_name}_path", options[:options] 471 399 assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1') 472 assert_named_route "#{full_prefix}/1;edit", " edit_#{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') 473 401 assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml') 474 assert_named_route "#{full_prefix}/new.xml", "formatted_ new_#{name_prefix}#{singular_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') 475 403 assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') 476 assert_named_route "#{full_prefix}/1 ;edit.xml", "formatted_edit_#{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') 477 405 yield options[:options] if block_given? 478 406 end … … 484 412 new_path = "#{full_path}/new" 485 413 edit_path = "#{full_path};edit" 486 formatted_edit_path = "#{full_path} ;edit.xml"414 formatted_edit_path = "#{full_path}.xml;edit" 487 415 488 416 with_options options[:options] do |controller| … … 521 449 522 450 full_path = "/#{options[:path_prefix]}#{singleton_name}" 523 full_name = "#{options[:name_prefix]}#{singleton_name}" 524 525 assert_named_route "#{full_path}", "#{full_name}_path", options[:options] 526 assert_named_route "#{full_path}/new", "new_#{full_name}_path", options[:options] 527 assert_named_route "#{full_path};edit", "edit_#{full_name}_path", options[:options] 528 assert_named_route "#{full_path}.xml", "formatted_#{full_name}_path", options[:options].merge(:format => 'xml') 529 assert_named_route "#{full_path}/new.xml", "formatted_new_#{full_name}_path", options[:options].merge(:format => 'xml') 530 assert_named_route "#{full_path};edit.xml", "formatted_edit_#{full_name}_path", options[:options].merge(:format => 'xml') 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') 531 458 end 532 459