Append development routes after reload hook

Allow appended root routes to take precedence over internal
welcome controller.
This commit is contained in:
Gannon McGibbon 2020-08-04 12:32:37 -04:00
parent ca8fde522a
commit 91247a02c6
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 "/"