Skip to content

Commit

Permalink
an enhanced MailDeliveryJob that propagates smtp_settings #2070
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Nov 21, 2024
1 parent 280e2e0 commit 584c47a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/jobs/enhanced_mail_delivery_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class EnhancedMailDeliveryJob < ActionMailer::MailDeliveryJob
# makes sure any changes to the smtp and host settings are picked up without having to restart delayed job
before_perform do
# make sure the SMTP,site_base_host configuration is in sync with current SEEK settings
Seek::Config.smtp_propagate
Seek::Config.site_base_host_propagate
end
end
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Application < Rails::Application
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', 'overrides', '**', '*.{rb,yml}')] unless Rails.env.test?

config.active_record.belongs_to_required_by_default = false
config.action_mailer.delivery_job = 'ActionMailer::MailDeliveryJob' # Can remove after updating defaults
config.action_mailer.delivery_job = 'EnhancedMailDeliveryJob' # sets the configured SMTP settngs before each run
config.action_mailer.preview_path = "#{Rails.root}/test/mailers/previews" # For some reason it is looking in spec/ by default
end
end
29 changes: 29 additions & 0 deletions test/unit/jobs/enhanced_mail_delivery_job_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'test_helper'
require 'minitest/mock'

class EnhancedMailDeliveryJobTest < ActiveSupport::TestCase
test 'perform' do
with_config_value(:email_enabled, true) do

assert_enqueued_jobs(1, only: EnhancedMailDeliveryJob, queue: QueueNames::MAILERS) do
Mailer.test_email('[email protected]').deliver_later
end

smtp_propagate_called = false
site_base_host_propagate_called = false

Seek::Config.stub :smtp_propagate, ->{smtp_propagate_called = true} do
Seek::Config.stub :site_base_host_propagate, ->{site_base_host_propagate_called = true} do
assert_emails 1 do
assert_performed_jobs(1, only: EnhancedMailDeliveryJob) do
Mailer.test_email('[email protected]').deliver_later
end
end
end
end

assert smtp_propagate_called
assert site_base_host_propagate_called
end
end
end

0 comments on commit 584c47a

Please sign in to comment.