diff options
author | Erick Reyna <ereyna@nearsoft.com> | 2016-11-17 16:32:49 -0600 |
---|---|---|
committer | Erick Reyna <ereyna@nearsoft.com> | 2016-11-18 15:12:13 -0600 |
commit | c79848e1e7c16d36a4af87c317422e17e04cde39 (patch) | |
tree | ae5cd91e36acc218b5ceefae6475b0dfa29bc4bb | |
parent | 7a3be90dce82031952e9abe07d9de7aedf1cb521 (diff) | |
download | rails-c79848e1e7c16d36a4af87c317422e17e04cde39.tar.gz rails-c79848e1e7c16d36a4af87c317422e17e04cde39.tar.bz2 rails-c79848e1e7c16d36a4af87c317422e17e04cde39.zip |
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.
-rw-r--r-- | actionpack/CHANGELOG.md | 14 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 10 | ||||
-rw-r--r-- | railties/test/application/rake/single_resource_test.rb | 33 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 6 |
4 files changed, 51 insertions, 12 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index f477d18c6a..9b6dcd7af3 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,11 +1,17 @@ -* Fixes multiple calls to `logger.fatal` instead of a single call, - for every line in an exception backtrace, when printing trace +* 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, + for every line in an exception backtrace, when printing trace from `DebugExceptions` middleware. - + Fixes #26134 *Vipul A M* - + * Add support for arbitrary hashes in strong parameters: ```ruby diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b39d367f7f..4efde09b8b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1244,11 +1244,11 @@ module ActionDispatch # the plural): # # GET /profile/new - # POST /profile # GET /profile # GET /profile/edit # PATCH/PUT /profile # DELETE /profile + # POST /profile # # === Options # Takes same options as +resources+. @@ -1266,15 +1266,15 @@ module ActionDispatch concerns(options[:concerns]) if options[:concerns] - collection do - post :create - end if parent_resource.actions.include?(:create) - new do get :new end if parent_resource.actions.include?(:new) set_member_mappings_for_resource + + collection do + post :create + end if parent_resource.actions.include?(:create) end end diff --git a/railties/test/application/rake/single_resource_test.rb b/railties/test/application/rake/single_resource_test.rb new file mode 100644 index 0000000000..d23516d3b1 --- /dev/null +++ b/railties/test/application/rake/single_resource_test.rb @@ -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 diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 5fd5507453..1288d43231 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -159,13 +159,13 @@ module ApplicationTests end RUBY 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", "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", " 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` } assert_equal expected_output, output |