mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Append development routes after reload hook
Allow appended root routes to take precedence over internal welcome controller.
This commit is contained in:
parent
ca8fde522a
commit
91247a02c6
4 changed files with 47 additions and 16 deletions
|
@ -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) ##
|
## Rails 6.1.0.rc1 (November 02, 2020) ##
|
||||||
|
|
||||||
* Added `Railtie#server` hook called when Rails starts a server.
|
* Added `Railtie#server` hook called when Rails starts a server.
|
||||||
|
|
|
@ -82,20 +82,6 @@ module Rails
|
||||||
end
|
end
|
||||||
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
|
# Setup default session store if not already set in config/application.rb
|
||||||
initializer :setup_default_session_store, before: :build_middleware_stack do |app|
|
initializer :setup_default_session_store, before: :build_middleware_stack do |app|
|
||||||
unless app.config.session_store?
|
unless app.config.session_store?
|
||||||
|
@ -209,6 +195,22 @@ module Rails
|
||||||
end
|
end
|
||||||
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
|
# Set clearing dependencies after the finisher hook to ensure paths
|
||||||
# added in the hook are taken into account.
|
# added in the hook are taken into account.
|
||||||
initializer :set_clear_dependencies_hook, group: :all do |app|
|
initializer :set_clear_dependencies_hook, group: :all do |app|
|
||||||
|
|
|
@ -283,12 +283,12 @@ class LoadingTest < ActiveSupport::TestCase
|
||||||
require "#{rails_root}/config/environment"
|
require "#{rails_root}/config/environment"
|
||||||
|
|
||||||
get "/c"
|
get "/c"
|
||||||
assert_equal "3", last_response.body
|
assert_equal "5", last_response.body
|
||||||
|
|
||||||
app_file "db/schema.rb", ""
|
app_file "db/schema.rb", ""
|
||||||
|
|
||||||
get "/c"
|
get "/c"
|
||||||
assert_equal "7", last_response.body
|
assert_equal "11", last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
test "columns migrations also trigger reloading" do
|
test "columns migrations also trigger reloading" do
|
||||||
|
|
|
@ -82,6 +82,30 @@ module ApplicationTests
|
||||||
assert_equal "foo", last_response.body
|
assert_equal "foo", last_response.body
|
||||||
end
|
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
|
test "rails/welcome in production" do
|
||||||
app("production")
|
app("production")
|
||||||
get "/"
|
get "/"
|
||||||
|
|
Loading…
Reference in a new issue