Skip to content

Commit a25ac84

Browse files
committed
Do not mark routes as loaded during RoutesReloader#reload! call.
Do it in `RoutesReloader#execute!` instead of `RoutesReloader#reload!` so it could be called during application initialization without prematurely marking routes as loaded.
1 parent a8a72f5 commit a25ac84

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

railties/lib/rails/application/routes_reloader.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RoutesReloader
1010
attr_reader :route_sets, :paths, :external_routes, :loaded
1111
attr_accessor :eager_load
1212
attr_writer :run_after_load_paths # :nodoc:
13-
delegate :execute_if_updated, :execute, :updated?, to: :updater
13+
delegate :execute_if_updated, :updated?, to: :updater
1414

1515
def initialize
1616
@paths = []
@@ -21,7 +21,6 @@ def initialize
2121
end
2222

2323
def reload!
24-
@loaded = true
2524
clear!
2625
load_paths
2726
finalize!
@@ -30,6 +29,11 @@ def reload!
3029
revert
3130
end
3231

32+
def execute
33+
@loaded = true
34+
updater.execute
35+
end
36+
3337
def execute_unless_loaded
3438
unless @loaded
3539
execute

railties/test/application/routing_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,31 @@ def index
314314
assert_equal "WIN", last_response.body
315315
end
316316

317+
test "routes appending blocks after reload" do
318+
app_file "config/routes.rb", <<-RUBY
319+
Rails.application.routes.draw do
320+
get ':controller/:action'
321+
end
322+
RUBY
323+
324+
add_to_config <<-R
325+
config.before_eager_load do |app|
326+
app.reload_routes!
327+
end
328+
329+
config.after_initialize do |app|
330+
app.routes.append do
331+
get '/win' => lambda { |e| [200, {'Content-Type'=>'text/plain'}, ['WIN']] }
332+
end
333+
end
334+
R
335+
336+
app "production"
337+
338+
get "/win"
339+
assert_equal "WIN", last_response.body
340+
end
341+
317342
test "routes drawing from config/routes" do
318343
app_file "config/routes.rb", <<-RUBY
319344
AppTemplate::Application.routes.draw do

0 commit comments

Comments
 (0)