From b6e17b6a4b67ccc9fac5fe16741c3db720f00959 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Apr 2019 00:22:13 +0200 Subject: new config to opt-out from adding app directories to $LOAD_PATH --- railties/test/application/configuration_test.rb | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'railties/test/application') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 62d9b1c813..7c613585e0 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -4,6 +4,7 @@ require "isolation/abstract_unit" require "rack/test" require "env_helpers" require "set" +require "active_support/core_ext/string/starts_ends_with" class ::MyMailInterceptor def self.delivering_email(email); email; end @@ -1704,6 +1705,33 @@ module ApplicationTests end end + test "autoload paths are added to $LOAD_PATH by default" do + app "development" + + # Action Mailer modifies AS::Dependencies.autoload_paths in-place. + autoload_paths = ActiveSupport::Dependencies.autoload_paths + autoload_paths_from_app_and_engines = autoload_paths.reject do |path| + path.ends_with?("mailers/previews") + end + assert_equal true, Rails.configuration.add_autoload_paths_to_load_path + assert_empty autoload_paths_from_app_and_engines - $LOAD_PATH + + # Precondition, ensure we are testing something next. + assert_not_empty Rails.configuration.paths.load_paths + assert_empty Rails.configuration.paths.load_paths - $LOAD_PATH + end + + test "autoload paths are not added to $LOAD_PATH if opted-out" do + add_to_config "config.add_autoload_paths_to_load_path = false" + app "development" + + assert_empty ActiveSupport::Dependencies.autoload_paths & $LOAD_PATH + + # Precondition, ensure we are testing something next. + assert_not_empty Rails.configuration.paths.load_paths + assert_empty Rails.configuration.paths.load_paths - $LOAD_PATH + end + test "autoloading during initialization gets deprecation message and clearing if config.cache_classes is false" do app_file "lib/c.rb", <<~EOS class C -- cgit v1.2.3