From d77b79e1a8571dc4ed7c85cea4429b37fad91ea3 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Tue, 23 Apr 2024 15:47:17 -0400 Subject: [PATCH] Jobs Generator: Remove obsolete configuration The [introduction][] of `config/initializers/active_job.rb` was rendered obsolete by [rails/rails#43390][]. Additionally, the following Rails 7 defaults match the [existing configuration][], so there is no need to redeclare them. ```ruby Rails.application.config.action_mailer.deliver_later_queue_name => nil Rails.application.config.action_mailbox.queues.routing => nil Rails.application.config.active_storage.queues.analysis => nil Rails.application.config.active_storage.queues.purge => nil Rails.application.config.active_storage.queues.mirror => nil ``` This is relevant because the next release of Suspenders will only support `rails >= 7.0`. [introduction]: https://github.com/thoughtbot/suspenders/commit/38b530c0a6a86175791c95a8f793d31b07b97c2d [rails/rails#43390]: https://github.com/rails/rails/pull/43390 [existing configuration]: https://github.com/thoughtbot/suspenders/blob/bd40e33a585891afba380a7884284f5accc003cf/lib/suspenders/generators/jobs_generator.rb#L19-L23 --- lib/generators/suspenders/jobs_generator.rb | 10 ---------- lib/generators/templates/active_job/active_job.rb | 14 -------------- test/fixtures/files/active_job.rb | 14 -------------- test/generators/suspenders/jobs_generator_test.rb | 15 --------------- 4 files changed, 53 deletions(-) delete mode 100644 lib/generators/templates/active_job/active_job.rb delete mode 100644 test/fixtures/files/active_job.rb diff --git a/lib/generators/suspenders/jobs_generator.rb b/lib/generators/suspenders/jobs_generator.rb index 5657a029d..c9cfc1a70 100644 --- a/lib/generators/suspenders/jobs_generator.rb +++ b/lib/generators/suspenders/jobs_generator.rb @@ -1,7 +1,6 @@ module Suspenders module Generators class JobsGenerator < Rails::Generators::Base - source_root File.expand_path("../../templates/active_job", __FILE__) desc <<~MARKDOWN Installs Sidekiq for background job processing. MARKDOWN @@ -11,17 +10,8 @@ def add_sidekiq_gem Bundler.with_unbundled_env { run "bundle install" } end - def initialize_active_job - copy_file "active_job.rb", "config/initializers/active_job.rb" - end - def configure_active_job environment "config.active_job.queue_adapter = :sidekiq" - environment "config.action_mailer.deliver_later_queue_name = nil" - environment "config.action_mailbox.queues.routing = nil" - environment "config.active_storage.queues.analysis = nil" - environment "config.active_storage.queues.purge = nil" - environment "config.active_storage.queues.mirror = nil" environment "config.active_job.queue_adapter = :inline", env: "test" end diff --git a/lib/generators/templates/active_job/active_job.rb b/lib/generators/templates/active_job/active_job.rb deleted file mode 100644 index ce7cbd7c2..000000000 --- a/lib/generators/templates/active_job/active_job.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "active_job/logging" -require "active_job/log_subscriber" - -ActiveSupport::Notifications.unsubscribe("enqueue.active_job") - -module ActiveJob - module Logging - class EnqueueLogSubscriber < LogSubscriber - define_method :enqueue, instance_method(:enqueue) - end - end -end - -ActiveJob::Logging::EnqueueLogSubscriber.attach_to(:active_job) diff --git a/test/fixtures/files/active_job.rb b/test/fixtures/files/active_job.rb deleted file mode 100644 index ce7cbd7c2..000000000 --- a/test/fixtures/files/active_job.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "active_job/logging" -require "active_job/log_subscriber" - -ActiveSupport::Notifications.unsubscribe("enqueue.active_job") - -module ActiveJob - module Logging - class EnqueueLogSubscriber < LogSubscriber - define_method :enqueue, instance_method(:enqueue) - end - end -end - -ActiveJob::Logging::EnqueueLogSubscriber.attach_to(:active_job) diff --git a/test/generators/suspenders/jobs_generator_test.rb b/test/generators/suspenders/jobs_generator_test.rb index ef76ecf14..d2ae73d00 100644 --- a/test/generators/suspenders/jobs_generator_test.rb +++ b/test/generators/suspenders/jobs_generator_test.rb @@ -29,26 +29,11 @@ class JobsGeneratorTest < Rails::Generators::TestCase assert_match(/bundle install/, output) end - test "configures ActiveJob logging" do - expected_configuration = file_fixture("active_job.rb").read - - run_generator - - assert_file app_root("config/initializers/active_job.rb") do |file| - assert_equal(expected_configuration, file) - end - end - test "adds ActiveJob configuration to the application file" do run_generator assert_file app_root("config/application.rb") do |file| assert_match(/config.active_job.queue_adapter = :sidekiq/, file) - assert_match(/config.action_mailer.deliver_later_queue_name = nil/, file) - assert_match(/config.action_mailbox.queues.routing = nil/, file) - assert_match(/config.active_storage.queues.analysis = nil/, file) - assert_match(/config.active_storage.queues.purge = nil/, file) - assert_match(/config.active_storage.queues.mirror = nil/, file) end end