Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Copy shallow options from normal options when using scope

If the options :shallow_prefix and :shallow_path are not set in the
scope options then copy them from the normal :as and :path options
if they are set.

(cherry picked from commit af4c9b7)
  • Loading branch information...
commit 05bfc1884d50303ad51fa46c9e5e1b674fd11d75 1 parent 09c6c85
@pixeltrix pixeltrix authored
View
3  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -698,7 +698,8 @@ def scope(*args)
options[:constraints] ||= {}
unless shallow?
- options[:shallow_path] = options[:path] if args.any?
+ options[:shallow_path] ||= options[:path] if options.key?(:path)
+ options[:shallow_prefix] ||= options[:as] if options.key?(:as)
end
if options[:constraints].is_a?(Hash)
View
48 actionpack/test/dispatch/routing_test.rb
@@ -3134,6 +3134,54 @@ def test_shallow_path_and_prefix_are_not_added_to_non_shallow_routes
assert_equal 'project_files#destroy', @response.body
end
+ def test_scope_path_is_copied_to_shallow_path
+ draw do
+ scope path: 'foo' do
+ resources :posts do
+ resources :comments, shallow: true
+ end
+ end
+ end
+
+ assert_equal '/foo/comments/1', comment_path('1')
+ end
+
+ def test_scope_as_is_copied_to_shallow_prefix
+ draw do
+ scope as: 'foo' do
+ resources :posts do
+ resources :comments, shallow: true
+ end
+ end
+ end
+
+ assert_equal '/comments/1', foo_comment_path('1')
+ end
+
+ def test_scope_shallow_prefix_is_not_overwritten_by_as
+ draw do
+ scope as: 'foo', shallow_prefix: 'bar' do
+ resources :posts do
+ resources :comments, shallow: true
+ end
+ end
+ end
+
+ assert_equal '/comments/1', bar_comment_path('1')
+ end
+
+ def test_scope_shallow_path_is_not_overwritten_by_path
+ draw do
+ scope path: 'foo', shallow_path: 'bar' do
+ resources :posts do
+ resources :comments, shallow: true
+ end
+ end
+ end
+
+ assert_equal '/bar/comments/1', comment_path('1')
+ end
+
private
def draw(&block)
Please sign in to comment.
Something went wrong with that request. Please try again.