提交 e4b04888 编写于 作者: M Matthew Draper

Preload Rails component gems in railties tests

上级 925e6d56
......@@ -314,6 +314,7 @@ def noop_email;end
end
test "the application can be eager loaded even when there are no frameworks" do
FileUtils.rm_rf("#{app_path}/app/jobs/application_job.rb")
FileUtils.rm_rf("#{app_path}/app/models/application_record.rb")
FileUtils.rm_rf("#{app_path}/app/mailers/application_mailer.rb")
FileUtils.rm_rf("#{app_path}/config/environments")
......
......@@ -174,6 +174,7 @@ def with_bare_config
test "ARGV is mutated as expected" do
require "#{app_path}/config/environment"
require "rails/command"
Rails::Command.const_set("APP_PATH", "rails/all")
FileUtils.cd(rails_root) do
......
......@@ -211,7 +211,7 @@ def show
test "database middleware doesn't initialize when activerecord is not in frameworks" do
use_frameworks []
require "#{app_path}/config/environment"
assert_nil defined?(ActiveRecord::Base)
assert !defined?(ActiveRecord::Base) || ActiveRecord.autoload?(:Base)
end
test "use schema cache dump" do
......
......@@ -299,7 +299,7 @@ def controller(name, contents)
end
def use_frameworks(arr)
to_remove = [:actionmailer, :activerecord] - arr
to_remove = [:actionmailer, :activerecord, :activestorage, :activejob] - arr
if to_remove.include?(:activerecord)
remove_from_config "config.active_record.*"
......@@ -329,4 +329,22 @@ class ActiveSupport::TestCase
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
f.puts "require 'rails/all'"
end
# Fake 'Bundler.require' -- we run using the repo's Gemfile, not an
# app-specific one: we don't want to require every gem that lists.
contents = File.read("#{app_template_path}/config/application.rb")
contents.sub!(/^Bundler\.require.*/, "%w(turbolinks).each { |r| require r }")
File.write("#{app_template_path}/config/application.rb", contents)
require "rails"
require "active_model"
require "active_job"
require "active_record"
require "action_controller"
require "action_mailer"
require "action_view"
require "active_storage"
require "action_cable"
require "sprockets"
end unless defined?(RAILS_ISOLATED_ENGINE)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册