Skip to content

Commit fe43770

Browse files
committed
Restore set_autoload_path triggering before bootstrap
Fixes rails#43205.
1 parent 766b84d commit fe43770

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

railties/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
* Fix a regression in which autoload paths were initialized too late.
4+
5+
*Xavier Noria*
6+
17
## Rails 7.0.0.alpha2 (September 15, 2021) ##
28

39
* Fix activestorage dependency in the npm package.

railties/lib/rails/application/bootstrap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module Bootstrap
6666

6767
# We setup the once autoloader this early so that engines and applications
6868
# are able to autoload from these paths during initialization.
69-
initializer :setup_once_autoloader do
69+
initializer :setup_once_autoloader, after: :set_eager_load_paths, before: :bootstrap_hook do
7070
autoloader = Rails.autoloaders.once
7171

7272
ActiveSupport::Dependencies.autoload_once_paths.freeze

railties/lib/rails/engine.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,12 @@ def load_seed
570570
$LOAD_PATH.uniq!
571571
end
572572

573-
initializer :set_autoload_once_paths, before: :setup_once_autoloader do
574-
config.autoload_once_paths.freeze
573+
initializer :set_autoload_paths, before: :bootstrap_hook do
574+
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
575575
ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
576-
end
577576

578-
initializer :set_autoload_paths, before: :setup_main_autoloader do
579577
config.autoload_paths.freeze
580-
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
578+
config.autoload_once_paths.freeze
581579
end
582580

583581
initializer :set_eager_load_paths, before: :bootstrap_hook do

railties/test/railties/engine_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,26 @@ class AddFirstNameToUsers < ActiveRecord::Migration::Current
233233
assert_equal "Another", Another.name
234234
end
235235

236+
test "when the bootstrap hook runs, autoload paths are set" do
237+
$test_autoload_once_paths = []
238+
$test_autoload_paths = []
239+
240+
add_to_config <<~RUBY
241+
# Unrealistic configuration, but keeps the test simple.
242+
config.autoload_once_paths << "#{app_path}/app/helpers"
243+
244+
initializer "inspect autoload paths", after: :bootstrap_hook do
245+
$test_autoload_once_paths += ActiveSupport::Dependencies.autoload_once_paths
246+
$test_autoload_paths += ActiveSupport::Dependencies.autoload_paths
247+
end
248+
RUBY
249+
250+
boot_rails
251+
252+
assert_includes $test_autoload_once_paths, "#{app_path}/app/helpers"
253+
assert_includes $test_autoload_paths, "#{app_path}/app/controllers"
254+
end
255+
236256
test "puts its models directory on autoload path" do
237257
@plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end"
238258
boot_rails

0 commit comments

Comments
 (0)