mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23611 from abhishekjain16/routes_options
Fix routes to match verb and URL path with -g option also.
This commit is contained in:
commit
8c53b41293
2 changed files with 12 additions and 3 deletions
|
@ -84,14 +84,15 @@ module ActionDispatch
|
|||
if filter.is_a?(Hash) && filter[:controller]
|
||||
{ controller: /#{filter[:controller].downcase.sub(/_?controller\z/, '').sub('::', '/')}/ }
|
||||
elsif filter
|
||||
{ controller: /#{filter}/, action: /#{filter}/ }
|
||||
{ controller: /#{filter}/, action: /#{filter}/, verb: /#{filter}/, name: /#{filter}/, path: /#{filter}/ }
|
||||
end
|
||||
end
|
||||
|
||||
def filter_routes(filter)
|
||||
if filter
|
||||
@routes.select do |route|
|
||||
filter.any? { |default, value| route.defaults[default] =~ value }
|
||||
route_wrapper = RouteWrapper.new(route)
|
||||
filter.any? { |default, value| route_wrapper.send(default) =~ value }
|
||||
end
|
||||
else
|
||||
@routes
|
||||
|
|
|
@ -179,12 +179,20 @@ module ApplicationTests
|
|||
app_file "config/routes.rb", <<-RUBY
|
||||
Rails.application.routes.draw do
|
||||
get '/cart', to: 'cart#show'
|
||||
get '/basketball', to: 'basketball#index'
|
||||
post '/cart', to: 'cart#create'
|
||||
get '/basketballs', to: 'basketball#index'
|
||||
end
|
||||
RUBY
|
||||
|
||||
output = Dir.chdir(app_path){ `bin/rails routes -g show` }
|
||||
assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output
|
||||
|
||||
output = Dir.chdir(app_path){ `bin/rails routes -g POST` }
|
||||
assert_equal "Prefix Verb URI Pattern Controller#Action\n POST /cart(.:format) cart#create\n", output
|
||||
|
||||
output = Dir.chdir(app_path){ `bin/rails routes -g basketballs` }
|
||||
assert_equal " Prefix Verb URI Pattern Controller#Action\n" \
|
||||
"basketballs GET /basketballs(.:format) basketball#index\n", output
|
||||
end
|
||||
|
||||
def test_rake_routes_with_controller_search_key
|
||||
|
|
Loading…
Reference in a new issue