提交 c18961f1 编写于 作者: N Nicholas Seckar

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
上级 4a3ec21b
......@@ -92,8 +92,8 @@ def default=(default)
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 @@ def traverse_to_controller(segments, start_at = 0)
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?
......
......@@ -711,6 +711,20 @@ def test_paths_escaped
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'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册