Skip to content

Commit 92d9231

Browse files
authored
Merge pull request rails#52409 from Shopify/multiple_path_mapping_deprecation
Deprecate multiple path route mapping
2 parents 27f3fa7 + c40ff50 commit 92d9231

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

actionpack/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
* Deprecate drawing routes with multiple paths to make routing faster.
2+
You may use `with_options` or a loop to make drawing multiple paths easier.
3+
4+
```ruby
5+
# Before
6+
get "/users", "/other_path", to: "users#index"
7+
8+
# After
9+
get "/users", to: "users#index"
10+
get "/other_path", to: "users#index"
11+
```
12+
13+
*Gannon McGibbon*
14+
115
* Make `http_cache_forever` use `immutable: true`
216

317
*Nate Matykiewicz*

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,11 @@ def path_scope(path)
19341934
end
19351935

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

actionpack/test/dispatch/routing_test.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ def test_projects_people
763763

764764
member do
765765
put :accessible_projects
766-
post :resend, :generate_new_password
766+
post :resend
767+
post :generate_new_password
767768
end
768769
end
769770
end
@@ -812,7 +813,8 @@ def test_projects_posts
812813
draw do
813814
resources :projects do
814815
resources :posts do
815-
get :archive, :toggle_view, on: :collection
816+
get :archive, on: :collection
817+
get :toggle_view, on: :collection
816818
post :preview, on: :member
817819

818820
resource :subscription
@@ -1533,8 +1535,10 @@ def test_index
15331535
end
15341536

15351537
def test_match_with_many_paths_containing_a_slash
1536-
draw do
1537-
get "get/first", "get/second", "get/third", to: "get#show"
1538+
assert_deprecated(ActionDispatch.deprecator) do
1539+
draw do
1540+
get "get/first", "get/second", "get/third", to: "get#show"
1541+
end
15381542
end
15391543

15401544
get "/get/first"
@@ -1570,9 +1574,11 @@ def test_match_shorthand_inside_namespace
15701574
end
15711575

15721576
def test_match_shorthand_with_multiple_paths_inside_namespace
1573-
draw do
1574-
namespace :proposals do
1575-
put "activate", "inactivate"
1577+
assert_deprecated(ActionDispatch.deprecator) do
1578+
draw do
1579+
namespace :proposals do
1580+
put "activate", "inactivate"
1581+
end
15761582
end
15771583
end
15781584

0 commit comments

Comments
 (0)