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

Skip Active Storage and Action Mailer if Active Job is skipped

If you use either of these frameworks, Active Job is used. That means
that only skipping Active Job will not really skip it, and whenever
app:update runs, Active Job will be added back.
This commit is contained in:
Étienne Barrié 2022-06-14 18:04:28 +02:00
parent 0adc2347d9
commit 9578865329
4 changed files with 15 additions and 5 deletions

View file

@ -1,3 +1,7 @@
* Skip Active Storage and Action Mailer if Active Job is skipped.
*Étienne Barrié*
* Correctly check if frameworks are disabled when running app:update. * Correctly check if frameworks are disabled when running app:update.
*Étienne Barrié* and *Paulo Barros* *Étienne Barrié* and *Paulo Barros*

View file

@ -23,7 +23,7 @@ module Rails
options = { api: !!Rails.application.config.api_only, update: true } options = { api: !!Rails.application.config.api_only, update: true }
options[:skip_active_job] = !defined?(ActiveJob::Railtie) options[:skip_active_job] = !defined?(ActiveJob::Railtie)
options[:skip_active_record] = !defined?(ActiveRecord::Railtie) options[:skip_active_record] = !defined?(ActiveRecord::Railtie)
options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie) options[:skip_active_storage] = !defined?(ActiveStorage::Engine)
options[:skip_action_mailer] = !defined?(ActionMailer::Railtie) options[:skip_action_mailer] = !defined?(ActionMailer::Railtie)
options[:skip_action_mailbox] = !defined?(ActionMailbox::Engine) options[:skip_action_mailbox] = !defined?(ActionMailbox::Engine)
options[:skip_action_text] = !defined?(ActionText::Engine) options[:skip_action_text] = !defined?(ActionText::Engine)

View file

@ -190,12 +190,12 @@ module Rails
[ [
options.values_at( options.values_at(
:skip_active_record, :skip_active_record,
:skip_action_mailer,
:skip_test, :skip_test,
:skip_action_cable, :skip_action_cable,
:skip_active_job :skip_active_job
), ),
skip_active_storage?, skip_active_storage?,
skip_action_mailer?,
skip_action_mailbox?, skip_action_mailbox?,
skip_action_text? skip_action_text?
].flatten.none? ].flatten.none?
@ -223,7 +223,11 @@ module Rails
end end
def skip_active_storage? # :doc: def skip_active_storage? # :doc:
options[:skip_active_storage] || options[:skip_active_record] options[:skip_active_storage] || options[:skip_active_record] || options[:skip_active_job]
end
def skip_action_mailer? # :doc:
options[:skip_action_mailer] || options[:skip_active_job]
end end
def skip_action_mailbox? # :doc: def skip_action_mailbox? # :doc:

View file

@ -292,12 +292,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_app_update_preserves_skip_active_job def test_app_update_preserves_skip_active_job
app_root = File.join(destination_root, "myapp") app_root = File.join(destination_root, "myapp")
run_generator [ app_root, "--skip-active-job", "--skip-active-storage", "--skip-action-mailer" ] run_generator [ app_root, "--skip-active-job" ]
FileUtils.cd(app_root) do FileUtils.cd(app_root) do
config = "config/application.rb" config = "config/application.rb"
assert_no_changes -> { File.readlines(config).grep(/require /) } do assert_no_changes -> { File.readlines(config).grep(/require /) } do
system("yes | TEST=hi bin/rails app:update") quietly { system("yes | bin/rails app:update") }
end end
end end
end end
@ -599,6 +599,8 @@ class AppGeneratorTest < Rails::Generators::TestCase
end end
assert_file "config/application.rb" do |content| assert_file "config/application.rb" do |content|
assert_match(/#\s+require\s+["']active_job\/railtie["']/, content) assert_match(/#\s+require\s+["']active_job\/railtie["']/, content)
assert_match(/#\s+require\s+["']active_storage\/engine["']/, content)
assert_match(/#\s+require\s+["']action_mailer\/railtie["']/, content)
end end
end end