1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #25544 from piotrj/pj-issue-25488

Fix setting route's to in a scope
This commit is contained in:
Rafael França 2016-06-28 16:22:25 -03:00 committed by GitHub
commit af874cc57f
2 changed files with 21 additions and 1 deletions

View file

@ -1062,6 +1062,10 @@ module ActionDispatch
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 @@ module ActionDispatch
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 @@ to this:
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]

View file

@ -102,6 +102,18 @@ module ActionDispatch
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