1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Implement AS::Dependencies.verbose= compatibility for :zeitwerk mode

This commit is contained in:
Xavier Noria 2019-02-15 14:47:16 -08:00
parent a25282ed1e
commit 3aa3c0684d
2 changed files with 41 additions and 0 deletions

View file

@ -26,6 +26,11 @@ module ActiveSupport
cpath = object.is_a?(Module) ? object.name : object.to_s cpath = object.is_a?(Module) ? object.name : object.to_s
Rails.autoloaders.any? { |autoloader| autoloader.loaded?(cpath) } Rails.autoloaders.any? { |autoloader| autoloader.loaded?(cpath) }
end end
def verbose=(verbose)
l = verbose ? (logger || Rails.logger).method(:debug) : nil
Rails.autoloaders.each { |autoloader| autoloader.logger = l }
end
end end
class << self class << self

View file

@ -163,4 +163,40 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert_equal %i(main_autoloader), $zeitwerk_integration_reload_test assert_equal %i(main_autoloader), $zeitwerk_integration_reload_test
end end
test "verbose = true sets the debug method of the dependencies logger if present" do
boot
logger = Logger.new(File::NULL)
ActiveSupport::Dependencies.logger = logger
ActiveSupport::Dependencies.verbose = true
Rails.autoloaders.each do |autoloader|
assert_equal logger.method(:debug), autoloader.logger
end
end
test "verbose = true sets the debug method of the Rails logger as fallback" do
boot
ActiveSupport::Dependencies.verbose = true
Rails.autoloaders.each do |autoloader|
assert_equal Rails.logger.method(:debug), autoloader.logger
end
end
test "verbose = false sets loggers to nil" do
boot
ActiveSupport::Dependencies.verbose = true
Rails.autoloaders.each do |autoloader|
assert autoloader.logger
end
ActiveSupport::Dependencies.verbose = false
Rails.autoloaders.each do |autoloader|
assert_nil autoloader.logger
end
end
end end