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

Restrict frameworks to load in engine test

For avoid to affect tests. Also, `action_text:install` task execute
`yarn add`. This is an expensive and should be avoided if it is not needed.
This commit is contained in:
yuuji.yaginuma 2019-01-18 15:07:05 +09:00
parent 3127f5783e
commit 6adc3da727

View file

@ -87,11 +87,10 @@ module RailtiesTest
end
RUBY
restrict_frameworks
boot_rails
Dir.chdir(app_path) do
# Install Active Storage, Action Mailbox, and Action Text migration files first so as not to affect test.
`bundle exec rake active_storage:install action_mailbox:install action_text:install`
output = `bundle exec rake bukkits:install:migrations`
["CreateUsers", "AddLastNameToUsers", "CreateSessions"].each do |migration_name|
@ -174,11 +173,10 @@ module RailtiesTest
class CreateKeys < ActiveRecord::Migration::Current; end
RUBY
restrict_frameworks
boot_rails
Dir.chdir(app_path) do
# Install Active Storage, Action Mailbox, and Action Text migrations first so as not to affect test.
`bundle exec rake active_storage:install action_mailbox:install action_text:install`
output = `bundle exec rake railties:install:migrations`.split("\n")
assert_match(/Copied migration \d+_create_users\.core_engine\.rb from core_engine/, output.first)
@ -1509,5 +1507,25 @@ YAML
def app
Rails.application
end
# Restrict frameworks to load in order to avoid engine frameworks affect tests.
def restrict_frameworks
remove_from_config("require 'rails/all'")
remove_from_config("require_relative 'boot'")
remove_from_env_config("development", "config.active_storage.*")
frameworks = <<~RUBY
require "rails"
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
RUBY
environment = File.read("#{app_path}/config/application.rb")
File.open("#{app_path}/config/application.rb", "w") { |f| f.puts frameworks + "\n" + environment }
end
end
end