diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 2fe74c5b34a6c..31e786cdfd6e6 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -979,6 +979,14 @@ def named_route(name, path, options = {}) @set.add_named_route(name, path, options) end + # Added deprecation notice for anyone who already added a named route called "root". + # It'll be used as a shortcut for map.connect '' in Rails 2.0. + def root(*args, &proc) + super unless args.length >= 1 && proc.nil? + @set.add_named_route("root", *args) + end + deprecate :root => "(as the the label for a named route) will become a shortcut for map.connect '', so find another name" + def method_missing(route_name, *args, &proc) super unless args.length >= 1 && proc.nil? @set.add_named_route(route_name, *args) diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 18fcef5bc5172..9a41440e78c06 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -376,7 +376,7 @@ def test_url_with_no_action_specified def test_named_url_with_no_action_specified rs.draw do |map| - map.root '', :controller => 'content' + map.home '', :controller => 'content' map.connect ':controller/:action/:id' end @@ -384,14 +384,14 @@ def test_named_url_with_no_action_specified assert_equal '/', rs.generate(:controller => 'content') x = setup_for_named_route.new - assert_equal({:controller => 'content', :action => 'index', :use_route => :root, :only_path => false}, - x.send(:root_url)) + assert_equal({:controller => 'content', :action => 'index', :use_route => :home, :only_path => false}, + x.send(:home_url)) end def test_url_generated_when_forgetting_action [{:controller => 'content', :action => 'index'}, {:controller => 'content'}].each do |hash| rs.draw do |map| - map.root '', hash + map.home '', hash map.connect ':controller/:action/:id' end assert_equal '/', rs.generate({:action => nil}, {:controller => 'content', :action => 'hello'}) @@ -1582,6 +1582,18 @@ def test_recognize_with_conditions_and_format Object.send(:remove_const, :PeopleController) end + def test_deprecation_warning_for_root_route + Object.const_set(:PeopleController, Class.new) + + set.draw do |map| + assert_deprecated do + map.root('', :controller => "people") + end + end + ensure + Object.send(:remove_const, :PeopleController) + end + def test_generate_with_default_action set.draw do |map| map.connect "/people", :controller => "people" diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 8f5e9812ed645..09178b101873a 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Deprecated the name route "root" as it'll be used as a shortcut for map.connect '' in Rails 2.0 [DHH] + * Fixed that script/server running against Mongrel should tail the proper log regardless of the environment [DHH] * Update initializer to load Rails::VERSION as soon as possible. Closes #6698. [Nicholas Seckar]