Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use nested_scope? not shallow? to determine whether to copy options

The method `shallow?` returns false if the parent resource is a singleton so
we need to check if we're not inside a nested scope before copying the :path
and :as options to their shallow equivalents.

Fixes #14388.

(cherry picked from commit 924345abcff0101e3221f87d1d56d3d6517a79a4)

Conflicts:
	actionpack/CHANGELOG.md
  • Loading branch information...
commit a6b9ea2e21ae51f6dfea8cea757ee0ecbebcd87e 1 parent ed2c313
@pixeltrix pixeltrix authored
View
9 actionpack/CHANGELOG.md
@@ -1,3 +1,12 @@
+* The method `shallow?` returns false if the parent resource is a singleton so
+ we need to check if we're not inside a nested scope before copying the :path
+ and :as options to their shallow equivalents.
+
+ Fixes #14388.
+
+ *Andrew White*
+
+
## Rails 4.0.4 (March 14, 2014) ##
* Fix label translation for more than 10 nested elements.
View
6 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -697,7 +697,7 @@ def scope(*args)
options[:path] = args.flatten.join('/') if args.any?
options[:constraints] ||= {}
- unless shallow?
+ unless nested_scope?
options[:shallow_path] ||= options[:path] if options.key?(:path)
options[:shallow_prefix] ||= options[:as] if options.key?(:as)
end
@@ -1536,6 +1536,10 @@ def resource_method_scope? #:nodoc:
RESOURCE_METHOD_SCOPES.include? @scope[:scope_level]
end
+ def nested_scope? #:nodoc:
+ @scope[:scope_level] == :nested
+ end
+
def with_exclusive_scope
begin
old_name_prefix, old_path = @scope[:as], @scope[:path]
View
36 actionpack/test/dispatch/routing_test.rb
@@ -1945,6 +1945,42 @@ def test_shallow_nested_resources
assert_equal '/comments/3/preview', preview_comment_path(:id => '3')
end
+ def test_shallow_nested_resources_inside_resource
+ draw do
+ resource :membership, shallow: true do
+ resources :cards
+ end
+ end
+
+ get '/membership/cards'
+ assert_equal 'cards#index', @response.body
+ assert_equal '/membership/cards', membership_cards_path
+
+ get '/membership/cards/new'
+ assert_equal 'cards#new', @response.body
+ assert_equal '/membership/cards/new', new_membership_card_path
+
+ post '/membership/cards'
+ assert_equal 'cards#create', @response.body
+
+ get '/cards/1'
+ assert_equal 'cards#show', @response.body
+ assert_equal '/cards/1', card_path('1')
+
+ get '/cards/1/edit'
+ assert_equal 'cards#edit', @response.body
+ assert_equal '/cards/1/edit', edit_card_path('1')
+
+ put '/cards/1'
+ assert_equal 'cards#update', @response.body
+
+ patch '/cards/1'
+ assert_equal 'cards#update', @response.body
+
+ delete '/cards/1'
+ assert_equal 'cards#destroy', @response.body
+ end
+
def test_shallow_nested_resources_within_scope
draw do
scope '/hello' do
Please sign in to comment.
Something went wrong with that request. Please try again.