From db0ee287eedafd8b4ba07c5c139d8d4143094ae9 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 22 Oct 2021 15:58:08 +0200 Subject: [PATCH 1/2] Enable eager loading by default on CI systems This is a pattern we've been using for ages at Shopify. When you are running test locally, most of the time you run only a subset, so it's better to load as little code as possible to have a faster time to first test result. But when you are on CI, it's usally much preferable to eager load the whole application because you will likely need all the code anyway, and even if the test suite is split across runners, it's preferable to load all the code to ensure any codefile that may have side effects is loaded. This also ensure that if some autoloaded constants are not properly tested on CI, at least they'll be loaded and obvious errors (e.g. SyntaxError) will be caught on CI rather than during deploy. --- .../rails/app/templates/config/environments/test.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 44c9a0aeaf..2d0a02411f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -14,7 +14,7 @@ Rails.application.configure do # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true From d58f85b75ab5693ebc1414f65125e755772b78a1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 22 Oct 2021 16:35:10 +0200 Subject: [PATCH 2/2] Update railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt Co-authored-by: Alex Ghiculescu --- .../rails/app/templates/config/environments/test.rb.tt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 2d0a02411f..e186e37754 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -11,9 +11,9 @@ Rails.application.configure do # Turn false under Spring and add config.action_view.cache_template_loading = true config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance.