Skip to content

Commit c79848e

Browse files
author
Erick Reyna
committed
Fix incorrect output from rails routes when using singular resources issue rails#26606
Rails routes (even rake routes in previous versions) output showed incorrect routes when an application use resource :controller, implying that edit_controller_path match with controller#show. The order of the output has changed to correct this. View rails#26606 for more information. Added a test case, change unit test in rake to expect the new output. Since the output of resource :controller is changing, the string spected of the railties/test/application/rake_test.rb test_rails_routes_with_controller_environment had to be modified.
1 parent 7a3be90 commit c79848e

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

actionpack/CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
* Fixes multiple calls to `logger.fatal` instead of a single call,
2-
for every line in an exception backtrace, when printing trace
1+
* Fixes Incorrect output from rails routes when using singular resources.
2+
3+
Fixes #26606
4+
5+
*Erick Reyna*
6+
7+
* Fixes multiple calls to `logger.fatal` instead of a single call,
8+
for every line in an exception backtrace, when printing trace
39
from `DebugExceptions` middleware.
4-
10+
511
Fixes #26134
612

713
*Vipul A M*
8-
14+
915
* Add support for arbitrary hashes in strong parameters:
1016

1117
```ruby

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,11 +1244,11 @@ def resources_path_names(options)
12441244
# the plural):
12451245
#
12461246
# GET /profile/new
1247-
# POST /profile
12481247
# GET /profile
12491248
# GET /profile/edit
12501249
# PATCH/PUT /profile
12511250
# DELETE /profile
1251+
# POST /profile
12521252
#
12531253
# === Options
12541254
# Takes same options as +resources+.
@@ -1266,15 +1266,15 @@ def resource(*resources, &block)
12661266

12671267
concerns(options[:concerns]) if options[:concerns]
12681268

1269-
collection do
1270-
post :create
1271-
end if parent_resource.actions.include?(:create)
1272-
12731269
new do
12741270
get :new
12751271
end if parent_resource.actions.include?(:new)
12761272

12771273
set_member_mappings_for_resource
1274+
1275+
collection do
1276+
post :create
1277+
end if parent_resource.actions.include?(:create)
12781278
end
12791279
end
12801280

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require "isolation/abstract_unit"
2+
require "active_support/core_ext/string/strip"
3+
4+
class RakeTest < ActiveSupport::TestCase
5+
include ActiveSupport::Testing::Isolation
6+
7+
def setup
8+
build_app
9+
end
10+
11+
def teardown
12+
teardown_app
13+
end
14+
15+
def test_singular_resource_output_in_rake_routes
16+
app_file "config/routes.rb", <<-RUBY
17+
Rails.application.routes.draw do
18+
resource :post
19+
end
20+
RUBY
21+
expected_output = [" Prefix Verb URI Pattern Controller#Action",
22+
" new_post GET /post/new(.:format) posts#new",
23+
"edit_post GET /post/edit(.:format) posts#edit",
24+
" post GET /post(.:format) posts#show",
25+
" PATCH /post(.:format) posts#update",
26+
" PUT /post(.:format) posts#update",
27+
" DELETE /post(.:format) posts#destroy",
28+
" POST /post(.:format) posts#create\n"].join("\n")
29+
30+
output = Dir.chdir(app_path) { `bin/rails routes -c PostController` }
31+
assert_equal expected_output, output
32+
end
33+
end

railties/test/application/rake_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ def test_rails_routes_with_namespaced_controller_environment
159159
end
160160
RUBY
161161
expected_output = [" Prefix Verb URI Pattern Controller#Action",
162-
" admin_post POST /admin/post(.:format) admin/posts#create",
163162
" new_admin_post GET /admin/post/new(.:format) admin/posts#new",
164163
"edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit",
165-
" GET /admin/post(.:format) admin/posts#show",
164+
" admin_post GET /admin/post(.:format) admin/posts#show",
166165
" PATCH /admin/post(.:format) admin/posts#update",
167166
" PUT /admin/post(.:format) admin/posts#update",
168-
" DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n")
167+
" DELETE /admin/post(.:format) admin/posts#destroy",
168+
" POST /admin/post(.:format) admin/posts#create\n"].join("\n")
169169

170170
output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` }
171171
assert_equal expected_output, output

0 commit comments

Comments
 (0)