Merge pull request #52409 from Shopify/multiple_path_mapping_deprecation

Deprecate multiple path route mapping
This commit is contained in:
Gannon McGibbon 2024-07-26 22:42:17 -05:00 committed by GitHub
commit 92d9231627
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 7 deletions

View File

@ -1,3 +1,17 @@
* Deprecate drawing routes with multiple paths to make routing faster.
You may use `with_options` or a loop to make drawing multiple paths easier.
```ruby
# Before
get "/users", "/other_path", to: "users#index"
# After
get "/users", to: "users#index"
get "/other_path", to: "users#index"
```
*Gannon McGibbon*
* Make `http_cache_forever` use `immutable: true`
*Nate Matykiewicz*

View File

@ -1934,6 +1934,11 @@ module ActionDispatch
end
def map_match(paths, options)
ActionDispatch.deprecator.warn(<<-MSG.squish) if paths.count > 1
Mapping a route with multiple paths is deprecated and
will be removed in Rails 8.1. Please use multiple method calls instead.
MSG
if (on = options[:on]) && !VALID_ON_OPTIONS.include?(on)
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
end

View File

@ -763,7 +763,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
member do
put :accessible_projects
post :resend, :generate_new_password
post :resend
post :generate_new_password
end
end
end
@ -812,7 +813,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
draw do
resources :projects do
resources :posts do
get :archive, :toggle_view, on: :collection
get :archive, on: :collection
get :toggle_view, on: :collection
post :preview, on: :member
resource :subscription
@ -1533,8 +1535,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
def test_match_with_many_paths_containing_a_slash
draw do
get "get/first", "get/second", "get/third", to: "get#show"
assert_deprecated(ActionDispatch.deprecator) do
draw do
get "get/first", "get/second", "get/third", to: "get#show"
end
end
get "/get/first"
@ -1570,9 +1574,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
def test_match_shorthand_with_multiple_paths_inside_namespace
draw do
namespace :proposals do
put "activate", "inactivate"
assert_deprecated(ActionDispatch.deprecator) do
draw do
namespace :proposals do
put "activate", "inactivate"
end
end
end