Skip to content

Commit

Permalink
Disable eager loading in Rails 7
Browse files Browse the repository at this point in the history
Rails 7 eager loads classes in test environment when a CI is detected.

This behavior causes Zeitwerk issues when trying to eager load
Active Admin files placed under `test_apps/rails_70/app/admin/`, because
they are not excluded by `remove_active_admin_load_paths_from_rails_autoload_and_eager_load`

This commit ensures that eager loading is disabled in test app's test
environment
  • Loading branch information
tagliala committed Dec 27, 2021
1 parent da94430 commit 12ef798
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/support/rails_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@

copy_file File.expand_path("templates/models/tagging.rb", __dir__), "app/models/tagging.rb"

# Rails 7: do not eager load classes to prevent Zeitwerk errors in test_app
gsub_file "config/environments/test.rb", / config.eager_load = ENV\["CI"\].present\?/, <<-RUBY
config.eager_load = false
RUBY

gsub_file "config/environments/test.rb", / config.cache_classes = true/, <<-RUBY
config.cache_classes = !ENV['CLASS_RELOADING']
Expand Down

0 comments on commit 12ef798

Please sign in to comment.