diff options
author | Xavier Noria <fxn@hashref.com> | 2019-03-30 08:38:41 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2019-03-30 09:33:48 +0100 |
commit | 278f0dfeac03e9e9d57eae8f4618ff94d8584abe (patch) | |
tree | 5a81fac64ab373ff86f3b6f3499a1c175ad705e9 /railties | |
parent | 360ff0a5934e32f49a2328b32b413ff58d6d79f1 (diff) | |
download | rails-278f0dfeac03e9e9d57eae8f4618ff94d8584abe.tar.gz rails-278f0dfeac03e9e9d57eae8f4618ff94d8584abe.tar.bz2 rails-278f0dfeac03e9e9d57eae8f4618ff94d8584abe.zip |
fixes eager loading edge case in :zeitwerk mode
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/engine.rb | 7 | ||||
-rw-r--r-- | railties/test/application/zeitwerk_integration_test.rb | 28 |
2 files changed, 33 insertions, 2 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 07bd56c978..2b5afd51b8 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -567,12 +567,15 @@ module Rails ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths) ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths) - # Freeze so future modifications will fail rather than do nothing mysteriously config.autoload_paths.freeze - config.eager_load_paths.freeze config.autoload_once_paths.freeze end + initializer :set_eager_load_paths, before: :bootstrap_hook do + ActiveSupport::Dependencies._eager_load_paths.merge(config.eager_load_paths) + config.eager_load_paths.freeze + end + initializer :add_routing_paths do |app| routing_paths = paths["config/routes.rb"].existent diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb index c82b37d07d..e4a17e5a31 100644 --- a/railties/test/application/zeitwerk_integration_test.rb +++ b/railties/test/application/zeitwerk_integration_test.rb @@ -149,6 +149,34 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase assert $zeitwerk_integration_test_extras end + test "autoload directores not present in eager load paths are not eager loaded" do + $zeitwerk_integration_test_user = false + app_file "app/models/user.rb", "class User; end; $zeitwerk_integration_test_user = true" + + $zeitwerk_integration_test_lib = false + app_dir "lib" + app_file "lib/webhook_hacks.rb", "WebhookHacks = 1; $zeitwerk_integration_test_lib = true" + + $zeitwerk_integration_test_extras = false + app_dir "extras" + app_file "extras/websocket_hacks.rb", "WebsocketHacks = 1; $zeitwerk_integration_test_extras = true" + + add_to_config "config.autoload_paths << '#{app_path}/lib'" + add_to_config "config.autoload_once_paths << '#{app_path}/extras'" + + boot("production") + + assert $zeitwerk_integration_test_user + assert !$zeitwerk_integration_test_lib + assert !$zeitwerk_integration_test_extras + + assert WebhookHacks + assert WebsocketHacks + + assert $zeitwerk_integration_test_lib + assert $zeitwerk_integration_test_extras + end + test "autoload_paths are set as root dirs of main, and in the same order" do boot |