mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Should allow symbols in :only and :except in routes.
This commit is contained in:
@@ -367,9 +367,9 @@ module ActionDispatch
|
||||
|
||||
def actions
|
||||
if only = options[:only]
|
||||
only.map(&:to_sym)
|
||||
Array(only).map(&:to_sym)
|
||||
elsif except = options[:except]
|
||||
default_actions - except.map(&:to_sym)
|
||||
default_actions - Array(except).map(&:to_sym)
|
||||
else
|
||||
default_actions
|
||||
end
|
||||
@@ -443,7 +443,7 @@ module ActionDispatch
|
||||
def resource(*resources, &block)
|
||||
options = resources.extract_options!
|
||||
|
||||
if verify_common_behavior_for(:resource, resources, options, &block)
|
||||
if apply_common_behavior_for(:resource, resources, options, &block)
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -468,7 +468,7 @@ module ActionDispatch
|
||||
def resources(*resources, &block)
|
||||
options = resources.extract_options!
|
||||
|
||||
if verify_common_behavior_for(:resources, resources, options, &block)
|
||||
if apply_common_behavior_for(:resources, resources, options, &block)
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -591,7 +591,7 @@ module ActionDispatch
|
||||
path_names[name.to_sym] || name.to_s
|
||||
end
|
||||
|
||||
def verify_common_behavior_for(method, resources, options, &block)
|
||||
def apply_common_behavior_for(method, resources, options, &block)
|
||||
if resources.length > 1
|
||||
resources.each { |r| send(method, r, options, &block) }
|
||||
return true
|
||||
|
||||
@@ -104,7 +104,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
resources :posts, :only => [:index, :show]
|
||||
resources :posts, :only => [:index, :show] do
|
||||
resources :comments, :except => :destroy
|
||||
end
|
||||
|
||||
match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp
|
||||
|
||||
@@ -471,7 +473,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
def test_posts
|
||||
def test_resource_routes_with_only_and_except
|
||||
with_test_routes do
|
||||
get '/posts'
|
||||
assert_equal 'posts#index', @response.body
|
||||
@@ -481,9 +483,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||
assert_equal 'posts#show', @response.body
|
||||
assert_equal '/posts/1', post_path(:id => 1)
|
||||
|
||||
get '/posts/1/comments'
|
||||
assert_equal 'comments#index', @response.body
|
||||
assert_equal '/posts/1/comments', post_comments_path(:post_id => 1)
|
||||
|
||||
assert_raise(ActionController::RoutingError) { post '/posts' }
|
||||
assert_raise(ActionController::RoutingError) { put '/posts/1' }
|
||||
assert_raise(ActionController::RoutingError) { delete '/posts/1' }
|
||||
assert_raise(ActionController::RoutingError) { delete '/posts/1/comments' }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user