Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for :shallow in router not generating helpers for create, update,…

… and destroy actions when :only or :except are used

[#4900 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 9d3eeb905341aaad942ceb0e47bd04cced34d031 1 parent a55d832
Josh Kalderimis joshk authored jeremy committed
7 actionpack/lib/action_dispatch/routing/mapper.rb
View
@@ -536,6 +536,7 @@ def initialize(entity, options = {})
def member_name
name
end
+ alias_method :collection_name, :member_name
def nested_path
path
@@ -874,9 +875,9 @@ def name_for_action(action)
shallow_prefix = @scope[:module].blank? ? "" : "#{@scope[:module].tr('/', '_')}_"
case action
- when :index
+ when :index, :create
"#{name_prefix}#{parent_resource.collection_name}"
- when :show
+ when :show, :update, :destroy
if parent_resource.shallow?
"#{shallow_prefix}#{parent_resource.member_name}"
else
@@ -890,8 +891,6 @@ def name_for_action(action)
end
when :new
"new_#{name_prefix}#{parent_resource.member_name}"
- when :update, :create, :destroy
- nil
else
case @scope[:scope_level]
when :collection
40 actionpack/test/dispatch/routing_test.rb
View
@@ -142,6 +142,12 @@ def self.matches?(request)
resources :comments, :except => :destroy
end
+ resource :past, :only => :destroy
+ resource :present, :only => :update
+ resource :future, :only => :create
+ resources :relationships, :only => [:create, :destroy]
+ resources :friendships, :only => [:update]
+
shallow do
namespace :api do
resources :teams do
@@ -729,6 +735,38 @@ def test_resource_routes_with_only_and_except
end
end
+ def test_resource_routes_only_create_update_destroy
+ with_test_routes do
+ delete '/past'
+ assert_equal 'pasts#destroy', @response.body
+ assert_equal '/past', past_path
+
+ put '/present'
+ assert_equal 'presents#update', @response.body
+ assert_equal '/present', present_path
+
+ post '/future'
+ assert_equal 'futures#create', @response.body
+ assert_equal '/future', future_path
+ end
+ end
+
+ def test_resources_routes_only_create_update_destroy
+ with_test_routes do
+ post '/relationships'
+ assert_equal 'relationships#create', @response.body
+ assert_equal '/relationships', relationships_path
+
+ delete '/relationships/1'
+ assert_equal 'relationships#destroy', @response.body
+ assert_equal '/relationships/1', relationship_path(1)
+
+ put '/friendships/1'
+ assert_equal 'friendships#update', @response.body
+ assert_equal '/friendships/1', friendship_path(1)
+ end
+ end
+
def test_resource_with_slugs_in_ids
with_test_routes do
get '/posts/rails-rocks'
@@ -843,7 +881,7 @@ def test_nested_namespace
assert_equal '/account/admin/subscription', account_admin_subscription_path
end
end
-
+
def test_namespace_nested_in_resources
with_test_routes do
get '/clients/1/google/account'

1 comment on commit 9d3eeb9

Diego Plentz

related to issue #1167

Please sign in to comment.
Something went wrong with that request. Please try again.