提交 a0b1912f 编写于 作者: P Piotr Jakubowski

Fix setting route's to in a scope

Fixes #25488
97d7dc48 introduced a regression that resulted in ArgumentError when to
was in options of the scope and not of particular route.
上级 754e5bdf
......@@ -1062,6 +1062,10 @@ def merge_options_scope(parent, child) #:nodoc:
def merge_shallow_scope(parent, child) #:nodoc:
child ? true : false
end
def merge_to_scope(parent, child)
child
end
end
# Resource routing allows you to quickly declare all of the common routes
......@@ -1582,6 +1586,10 @@ def match(path, *rest)
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
end
if @scope[:to]
options[:to] ||= @scope[:to]
end
if @scope[:controller] && @scope[:action]
options[:to] ||= "#{@scope[:controller]}##{@scope[:action]}"
end
......@@ -2021,7 +2029,7 @@ def concerns(*args)
class Scope # :nodoc:
OPTIONS = [:path, :shallow_path, :as, :shallow_prefix, :module,
:controller, :action, :path_names, :constraints,
:shallow, :blocks, :defaults, :via, :format, :options]
:shallow, :blocks, :defaults, :via, :format, :options, :to]
RESOURCE_SCOPES = [:resource, :resources]
RESOURCE_METHOD_SCOPES = [:collection, :member, :new]
......
......@@ -102,6 +102,18 @@ def test_via_scope
assert_equal("PUT", fakeset.routes.first.verb)
end
def test_to_scope
fakeset = FakeSet.new
mapper = Mapper.new fakeset
mapper.scope(to: "posts#index") do
mapper.get :all
mapper.post :most
end
assert_equal "posts#index", fakeset.routes.to_a[0].defaults[:to]
assert_equal "posts#index", fakeset.routes.to_a[1].defaults[:to]
end
def test_map_slash
fakeset = FakeSet.new
mapper = Mapper.new fakeset
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册