diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-07-08 08:56:24 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-07-08 08:56:24 +0000 |
commit | c18961f185cb593873b72d1ffa67c640b2cd126f (patch) | |
tree | 08c40dabc2ceb97c2d331db4f37fb0ca0164b4bf | |
parent | 4a3ec21b6261374ad58f3bc337fc8a547b6c490d (diff) | |
download | rails-c18961f185cb593873b72d1ffa67c640b2cd126f.tar.gz rails-c18961f185cb593873b72d1ffa67c640b2cd126f.tar.bz2 rails-c18961f185cb593873b72d1ffa67c640b2cd126f.zip |
Routes now raise an exception if a path component is misconfigured.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1769 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 10 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 14 |
2 files changed, 21 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 32ce0db3aa..6b551e2533 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -92,8 +92,8 @@ module ActionController def initialize(key, options = {}) @key = key.to_sym - @default, @condition = options[:default], options[:condition] - @optional = options.key?(:default) + default, @condition = options[:default], options[:condition] + self.default = default if options.key?(:default) end def default_check(g) @@ -226,8 +226,12 @@ module ActionController class PathComponent < DynamicComponent #:nodoc: def optional?() true end - def default() '' end + def default() [] end def condition() nil end + + def default=(value) + raise RoutingError, "All path components have an implicit default of []" unless value == [] + end def write_generation(g) raise RoutingError, 'Path components must occur last' unless g.after.empty? diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index c68b1f70d3..3bc240b44d 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -711,6 +711,20 @@ class RouteSetTests < Test::Unit::TestCase assert_equal [], results['path'] end + def test_paths_do_not_accept_defaults + assert_raises(ActionController::RoutingError) do + rs.draw do |map| + rs.path 'file/*path', :controller => 'content', :action => 'show_file', :path => %w(fake default) + rs.connect ':controller/:action/:id' + end + end + + rs.draw do |map| + rs.path 'file/*path', :controller => 'content', :action => 'show_file', :path => [] + rs.connect ':controller/:action/:id' + end + end + def test_backwards rs.draw do |map| rs.connect 'page/:id/:action', :controller => 'pages', :action => 'show' |