1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #39980 from gmcgibbon/route_append_order

Append development routes after reload hook
This commit is contained in:
Gannon McGibbon 2020-11-09 18:19:26 -05:00 committed by GitHub
commit 47a4201d8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 16 deletions

View file

@ -1,3 +1,8 @@
* Allow appended root routes to take precedence over internal welcome controller.
*Gannon McGibbon*
## Rails 6.1.0.rc1 (November 02, 2020) ##
* Added `Railtie#server` hook called when Rails starts a server.

View file

@ -82,20 +82,6 @@ module Rails
end
end
initializer :add_builtin_route do |app|
if Rails.env.development?
app.routes.prepend do
get "/rails/info/properties" => "rails/info#properties", internal: true
get "/rails/info/routes" => "rails/info#routes", internal: true
get "/rails/info" => "rails/info#index", internal: true
end
app.routes.append do
get "/" => "rails/welcome#index", internal: true
end
end
end
# Setup default session store if not already set in config/application.rb
initializer :setup_default_session_store, before: :build_middleware_stack do |app|
unless app.config.session_store?
@ -209,6 +195,22 @@ module Rails
end
end
initializer :add_builtin_route do |app|
if Rails.env.development?
app.routes.prepend do
get "/rails/info/properties" => "rails/info#properties", internal: true
get "/rails/info/routes" => "rails/info#routes", internal: true
get "/rails/info" => "rails/info#index", internal: true
end
app.routes.append do
get "/" => "rails/welcome#index", internal: true
end
routes_reloader.execute
end
end
# Set clearing dependencies after the finisher hook to ensure paths
# added in the hook are taken into account.
initializer :set_clear_dependencies_hook, group: :all do |app|

View file

@ -283,12 +283,12 @@ class LoadingTest < ActiveSupport::TestCase
require "#{rails_root}/config/environment"
get "/c"
assert_equal "3", last_response.body
assert_equal "5", last_response.body
app_file "db/schema.rb", ""
get "/c"
assert_equal "7", last_response.body
assert_equal "11", last_response.body
end
test "columns migrations also trigger reloading" do

View file

@ -82,6 +82,30 @@ module ApplicationTests
assert_equal "foo", last_response.body
end
test "appended root takes precedence over internal welcome controller" do
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render plain: "foo"
end
end
RUBY
app_file "config/routes.rb", <<-RUBY
Rails.application.routes.draw do
end
Rails.application.routes.append do
get "/", to: "foo#index"
end
RUBY
app("development")
get "/"
assert_equal "foo", last_response.body
end
test "rails/welcome in production" do
app("production")
get "/"