Skip to content

Commit

Permalink
Restore set_autoload_path triggering before bootstrap
Browse files Browse the repository at this point in the history
Fixes #43205.
  • Loading branch information
fxn committed Oct 4, 2021
1 parent 766b84d commit fe43770
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,9 @@
## Unreleased

* Fix a regression in which autoload paths were initialized too late.

*Xavier Noria*

## Rails 7.0.0.alpha2 (September 15, 2021) ##

* Fix activestorage dependency in the npm package.
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application/bootstrap.rb
Expand Up @@ -66,7 +66,7 @@ module Bootstrap

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

ActiveSupport::Dependencies.autoload_once_paths.freeze
Expand Down
8 changes: 3 additions & 5 deletions railties/lib/rails/engine.rb
Expand Up @@ -570,14 +570,12 @@ def load_seed
$LOAD_PATH.uniq!
end

initializer :set_autoload_once_paths, before: :setup_once_autoloader do
config.autoload_once_paths.freeze
initializer :set_autoload_paths, before: :bootstrap_hook do
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
end

initializer :set_autoload_paths, before: :setup_main_autoloader do
config.autoload_paths.freeze
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
config.autoload_once_paths.freeze
end

initializer :set_eager_load_paths, before: :bootstrap_hook do
Expand Down
20 changes: 20 additions & 0 deletions railties/test/railties/engine_test.rb
Expand Up @@ -233,6 +233,26 @@ class AddFirstNameToUsers < ActiveRecord::Migration::Current
assert_equal "Another", Another.name
end

test "when the bootstrap hook runs, autoload paths are set" do
$test_autoload_once_paths = []
$test_autoload_paths = []

add_to_config <<~RUBY
# Unrealistic configuration, but keeps the test simple.
config.autoload_once_paths << "#{app_path}/app/helpers"
initializer "inspect autoload paths", after: :bootstrap_hook do
$test_autoload_once_paths += ActiveSupport::Dependencies.autoload_once_paths
$test_autoload_paths += ActiveSupport::Dependencies.autoload_paths
end
RUBY

boot_rails

assert_includes $test_autoload_once_paths, "#{app_path}/app/helpers"
assert_includes $test_autoload_paths, "#{app_path}/app/controllers"
end

test "puts its models directory on autoload path" do
@plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end"
boot_rails
Expand Down

0 comments on commit fe43770

Please sign in to comment.