aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/zeitwerk_integration_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/application/zeitwerk_integration_test.rb')
-rw-r--r--railties/test/application/zeitwerk_integration_test.rb70
1 files changed, 50 insertions, 20 deletions
diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb
index 8a8ca18ebf..c82b37d07d 100644
--- a/railties/test/application/zeitwerk_integration_test.rb
+++ b/railties/test/application/zeitwerk_integration_test.rb
@@ -47,6 +47,31 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert_equal 0, Rails.autoloaders.count
end
+ test "autoloaders inflect with Active Support" do
+ app_file "config/initializers/inflections.rb", <<-RUBY
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
+ inflect.acronym 'RESTful'
+ end
+ RUBY
+
+ app_file "app/controllers/restful_controller.rb", <<-RUBY
+ class RESTfulController < ApplicationController
+ end
+ RUBY
+
+ boot
+
+ basename = "restful_controller"
+ abspath = "#{Rails.root}/app/controllers/#{basename}.rb"
+ camelized = "RESTfulController"
+
+ Rails.autoloaders.each do |autoloader|
+ assert_equal camelized, autoloader.inflector.camelize(basename, abspath)
+ end
+
+ assert RESTfulController
+ end
+
test "constantize returns the value stored in the constant" do
app_file "app/models/admin/user.rb", "class Admin::User; end"
boot
@@ -124,22 +149,27 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert $zeitwerk_integration_test_extras
end
- test "autoload paths that are below Gem.path go to the once autoloader" do
- app_dir "extras"
- add_to_config 'config.autoload_paths << "#{Rails.root}/extras"'
-
- # Mocks Gem.path to include the extras directory.
- Gem.singleton_class.prepend(
- Module.new do
- def path
- super + ["#{Rails.root}/extras"]
- end
- end
- )
+ test "autoload_paths are set as root dirs of main, and in the same order" do
+ boot
+
+ existing_autoload_paths = deps.autoload_paths.select { |dir| File.directory?(dir) }
+ assert_equal existing_autoload_paths, Rails.autoloaders.main.dirs
+ end
+
+ test "autoload_once_paths go to the once autoloader, and in the same order" do
+ extras = %w(e1 e2 e3)
+ extras.each do |extra|
+ app_dir extra
+ add_to_config %(config.autoload_once_paths << "\#{Rails.root}/#{extra}")
+ end
+
boot
- assert_not_includes Rails.autoloaders.main.dirs, "#{app_path}/extras"
- assert_includes Rails.autoloaders.once.dirs, "#{app_path}/extras"
+ extras = extras.map { |extra| "#{app_path}/#{extra}" }
+ extras.each do |extra|
+ assert_not_includes Rails.autoloaders.main.dirs, extra
+ end
+ assert_equal extras, Rails.autoloaders.once.dirs
end
test "clear reloads the main autoloader, and does not reload the once one" do
@@ -164,7 +194,7 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert_equal %i(main_autoloader), $zeitwerk_integration_reload_test
end
- test "verbose = true sets the debug method of the dependencies logger if present" do
+ test "verbose = true sets the dependencies logger if present" do
boot
logger = Logger.new(File::NULL)
@@ -172,17 +202,17 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
ActiveSupport::Dependencies.verbose = true
Rails.autoloaders.each do |autoloader|
- assert_equal logger.method(:debug), autoloader.logger
+ assert_same logger, autoloader.logger
end
end
- test "verbose = true sets the debug method of the Rails logger as fallback" do
+ test "verbose = true sets the Rails logger as fallback" do
boot
ActiveSupport::Dependencies.verbose = true
Rails.autoloaders.each do |autoloader|
- assert_equal Rails.logger.method(:debug), autoloader.logger
+ assert_same Rails.logger, autoloader.logger
end
end
@@ -214,13 +244,13 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
Rails.autoloaders.logger = logger
Rails.autoloaders.each do |autoloader|
- assert_equal logger, autoloader.logger
+ assert_same logger, autoloader.logger
end
Rails.autoloaders.logger = Rails.logger
Rails.autoloaders.each do |autoloader|
- assert_equal Rails.logger.method(:debug), autoloader.logger
+ assert_same Rails.logger, autoloader.logger
end
Rails.autoloaders.logger = nil