提交 a47c84d5 编写于 作者: X Xavier Noria

Engines are reloaded in Zeitwerk mode [closes #35618]

上级 23392796
* In Zeitwerk mode, engines are now managed by the `main` autoloader. Engines may reference application constants, if the application is reloaded and we do not reload engines, they won't use the reloaded application code.
*Xavier Noria*
* Add support for supplying `locale` to `transliterate` and `parameterize`.
I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } })
......
......@@ -71,8 +71,7 @@ def setup_autoloaders
end
def autoload_once?(autoload_path)
Dependencies.autoload_once_paths.include?(autoload_path) ||
Gem.path.any? { |gem_path| autoload_path.to_s.start_with?(gem_path) }
Dependencies.autoload_once_paths.include?(autoload_path)
end
def freeze_autoload_paths
......
......@@ -149,22 +149,27 @@ class RESTfulController < ApplicationController
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
assert_not_includes Rails.autoloaders.main.dirs, "#{app_path}/extras"
assert_includes Rails.autoloaders.once.dirs, "#{app_path}/extras"
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
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册