aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/zeitwerk_integration_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2019-03-30 12:20:00 +0100
committerXavier Noria <fxn@hashref.com>2019-03-30 13:01:42 +0100
commita3e061def14b50b86d9366d45565a4ad2efb0b08 (patch)
tree595a53246a027879e527acc176e612f2b69713e6 /railties/test/application/zeitwerk_integration_test.rb
parent278f0dfeac03e9e9d57eae8f4618ff94d8584abe (diff)
downloadrails-a3e061def14b50b86d9366d45565a4ad2efb0b08.tar.gz
rails-a3e061def14b50b86d9366d45565a4ad2efb0b08.tar.bz2
rails-a3e061def14b50b86d9366d45565a4ad2efb0b08.zip
optimizes eager loading in :zeitwerk mode
During initialization, the eager load paths of engines are unshifted into AS::Dependencies.autoload_paths. After that, the collection is frozen. (See the initializers in railties/lib/rails/engine.rb.) Hence, there is no eager load path that is not an autoload path too, and so the array difference in the deleted code is always an empty array. Just do nothing.
Diffstat (limited to 'railties/test/application/zeitwerk_integration_test.rb')
-rw-r--r--railties/test/application/zeitwerk_integration_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb
index e4a17e5a31..a4320bbdc3 100644
--- a/railties/test/application/zeitwerk_integration_test.rb
+++ b/railties/test/application/zeitwerk_integration_test.rb
@@ -124,12 +124,26 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
app_file "app/models/user.rb", "class User; end; $zeitwerk_integration_test_user = true"
app_file "app/models/post.rb", "class Post; end; $zeitwerk_integration_test_post = true"
+
boot("production")
assert $zeitwerk_integration_test_user
assert $zeitwerk_integration_test_post
end
+ test "eager loading loads code in engines" do
+ $test_blog_engine_eager_loaded = false
+
+ engine("blog") do |bukkit|
+ bukkit.write("lib/blog.rb", "class BlogEngine < Rails::Engine; end")
+ bukkit.write("app/models/post.rb", "Post = $test_blog_engine_eager_loaded = true")
+ end
+
+ boot("production")
+
+ assert $test_blog_engine_eager_loaded
+ end
+
test "eager loading loads anything managed by Zeitwerk" do
$zeitwerk_integration_test_user = false
app_file "app/models/user.rb", "class User; end; $zeitwerk_integration_test_user = true"