mirror of https://github.com/rails/rails
Let the Action Pack autoload with Zeitwerk
This commit is contained in:
parent
c192feb3eb
commit
e933dc0b84
|
@ -22,6 +22,7 @@ require "action_view/testing/resolvers"
|
|||
require "action_dispatch"
|
||||
require "active_support/dependencies"
|
||||
require "active_model"
|
||||
require "zeitwerk"
|
||||
|
||||
module Rails
|
||||
class << self
|
||||
|
@ -159,16 +160,12 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
|
|||
|
||||
def with_autoload_path(path)
|
||||
path = File.join(__dir__, "fixtures", path)
|
||||
if ActiveSupport::Dependencies.autoload_paths.include?(path)
|
||||
Zeitwerk.with_loader do |loader|
|
||||
loader.push_dir(path)
|
||||
loader.setup
|
||||
yield
|
||||
else
|
||||
begin
|
||||
ActiveSupport::Dependencies.autoload_paths << path
|
||||
yield
|
||||
ensure
|
||||
ActiveSupport::Dependencies.autoload_paths.reject! { |p| p == path }
|
||||
ActiveSupport::Dependencies.clear
|
||||
end
|
||||
ensure
|
||||
loader.unload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
require "abstract_unit"
|
||||
require "timeout"
|
||||
require "concurrent/atomic/count_down_latch"
|
||||
require "zeitwerk"
|
||||
|
||||
Thread.abort_on_exception = true
|
||||
|
||||
module ActionController
|
||||
|
@ -173,18 +175,22 @@ module ActionController
|
|||
|
||||
def write_sleep_autoload
|
||||
path = File.expand_path("../fixtures", __dir__)
|
||||
ActiveSupport::Dependencies.autoload_paths << path
|
||||
Zeitwerk.with_loader do |loader|
|
||||
loader.push_dir(path)
|
||||
loader.ignore(File.join(path, "公共"))
|
||||
loader.setup
|
||||
|
||||
response.headers["Content-Type"] = "text/event-stream"
|
||||
response.stream.write "before load"
|
||||
sleep 0.01
|
||||
silence_warnings do
|
||||
::LoadMe
|
||||
response.headers["Content-Type"] = "text/event-stream"
|
||||
response.stream.write "before load"
|
||||
sleep 0.01
|
||||
silence_warnings do
|
||||
::LoadMe
|
||||
end
|
||||
response.stream.close
|
||||
latch.count_down
|
||||
ensure
|
||||
loader.unload
|
||||
end
|
||||
response.stream.close
|
||||
latch.count_down
|
||||
|
||||
ActiveSupport::Dependencies.autoload_paths.reject! { |p| p == path }
|
||||
end
|
||||
|
||||
def thread_locals
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_unit"
|
||||
require "fixtures/session_autoload_test/session_autoload_test/foo"
|
||||
|
||||
class CacheStoreTest < ActionDispatch::IntegrationTest
|
||||
class TestController < ActionController::Base
|
||||
|
|
Loading…
Reference in New Issue