From a0b1912fb077d47e1977cf1b38b884651756d853 Mon Sep 17 00:00:00 2001
From: Piotr Jakubowski <piotrj@gmail.com>
Date: Mon, 27 Jun 2016 21:02:19 +0200
Subject: Fix setting route's to in a scope

Fixes #25488
97d7dc4 introduced a regression that resulted in ArgumentError when to
was in options of the scope and not of particular route.
---
 actionpack/lib/action_dispatch/routing/mapper.rb | 10 +++++++++-
 actionpack/test/dispatch/mapper_test.rb          | 12 ++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 40b6500553..e2cf75da3a 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -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]
diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb
index 69098326b9..f6dd9272a6 100644
--- a/actionpack/test/dispatch/mapper_test.rb
+++ b/actionpack/test/dispatch/mapper_test.rb
@@ -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
-- 
cgit v1.2.3