mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix incorrect output from rails routes when using singular resources issue #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 #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.
This commit is contained in:
parent
7a3be90dce
commit
c79848e1e7
4 changed files with 51 additions and 12 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
* Fixes Incorrect output from rails routes when using singular resources.
|
||||||
|
|
||||||
|
Fixes #26606
|
||||||
|
|
||||||
|
*Erick Reyna*
|
||||||
|
|
||||||
* Fixes multiple calls to `logger.fatal` instead of a single call,
|
* Fixes multiple calls to `logger.fatal` instead of a single call,
|
||||||
for every line in an exception backtrace, when printing trace
|
for every line in an exception backtrace, when printing trace
|
||||||
from `DebugExceptions` middleware.
|
from `DebugExceptions` middleware.
|
||||||
|
|
|
@ -1244,11 +1244,11 @@ module ActionDispatch
|
||||||
# the plural):
|
# the plural):
|
||||||
#
|
#
|
||||||
# GET /profile/new
|
# GET /profile/new
|
||||||
# POST /profile
|
|
||||||
# GET /profile
|
# GET /profile
|
||||||
# GET /profile/edit
|
# GET /profile/edit
|
||||||
# PATCH/PUT /profile
|
# PATCH/PUT /profile
|
||||||
# DELETE /profile
|
# DELETE /profile
|
||||||
|
# POST /profile
|
||||||
#
|
#
|
||||||
# === Options
|
# === Options
|
||||||
# Takes same options as +resources+.
|
# Takes same options as +resources+.
|
||||||
|
@ -1266,15 +1266,15 @@ module ActionDispatch
|
||||||
|
|
||||||
concerns(options[:concerns]) if options[:concerns]
|
concerns(options[:concerns]) if options[:concerns]
|
||||||
|
|
||||||
collection do
|
|
||||||
post :create
|
|
||||||
end if parent_resource.actions.include?(:create)
|
|
||||||
|
|
||||||
new do
|
new do
|
||||||
get :new
|
get :new
|
||||||
end if parent_resource.actions.include?(:new)
|
end if parent_resource.actions.include?(:new)
|
||||||
|
|
||||||
set_member_mappings_for_resource
|
set_member_mappings_for_resource
|
||||||
|
|
||||||
|
collection do
|
||||||
|
post :create
|
||||||
|
end if parent_resource.actions.include?(:create)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
33
railties/test/application/rake/single_resource_test.rb
Normal file
33
railties/test/application/rake/single_resource_test.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
require "isolation/abstract_unit"
|
||||||
|
require "active_support/core_ext/string/strip"
|
||||||
|
|
||||||
|
class RakeTest < ActiveSupport::TestCase
|
||||||
|
include ActiveSupport::Testing::Isolation
|
||||||
|
|
||||||
|
def setup
|
||||||
|
build_app
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
teardown_app
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_singular_resource_output_in_rake_routes
|
||||||
|
app_file "config/routes.rb", <<-RUBY
|
||||||
|
Rails.application.routes.draw do
|
||||||
|
resource :post
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
expected_output = [" Prefix Verb URI Pattern Controller#Action",
|
||||||
|
" new_post GET /post/new(.:format) posts#new",
|
||||||
|
"edit_post GET /post/edit(.:format) posts#edit",
|
||||||
|
" post GET /post(.:format) posts#show",
|
||||||
|
" PATCH /post(.:format) posts#update",
|
||||||
|
" PUT /post(.:format) posts#update",
|
||||||
|
" DELETE /post(.:format) posts#destroy",
|
||||||
|
" POST /post(.:format) posts#create\n"].join("\n")
|
||||||
|
|
||||||
|
output = Dir.chdir(app_path) { `bin/rails routes -c PostController` }
|
||||||
|
assert_equal expected_output, output
|
||||||
|
end
|
||||||
|
end
|
|
@ -159,13 +159,13 @@ module ApplicationTests
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
expected_output = [" Prefix Verb URI Pattern Controller#Action",
|
expected_output = [" Prefix Verb URI Pattern Controller#Action",
|
||||||
" admin_post POST /admin/post(.:format) admin/posts#create",
|
|
||||||
" new_admin_post GET /admin/post/new(.:format) admin/posts#new",
|
" new_admin_post GET /admin/post/new(.:format) admin/posts#new",
|
||||||
"edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit",
|
"edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit",
|
||||||
" GET /admin/post(.:format) admin/posts#show",
|
" admin_post GET /admin/post(.:format) admin/posts#show",
|
||||||
" PATCH /admin/post(.:format) admin/posts#update",
|
" PATCH /admin/post(.:format) admin/posts#update",
|
||||||
" PUT /admin/post(.:format) admin/posts#update",
|
" PUT /admin/post(.:format) admin/posts#update",
|
||||||
" DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n")
|
" DELETE /admin/post(.:format) admin/posts#destroy",
|
||||||
|
" POST /admin/post(.:format) admin/posts#create\n"].join("\n")
|
||||||
|
|
||||||
output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` }
|
output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` }
|
||||||
assert_equal expected_output, output
|
assert_equal expected_output, output
|
||||||
|
|
Loading…
Reference in a new issue