Project

General

Profile

Feature #29914 » 0003-Fix-sending-mail-with-DeliveryJob-is-deprecated-2991.patch

Marius BĂLTEANU, 2021-03-30 18:41

View differences:

app/models/mailer.rb
642 642
  # Rake will likely end, causing the in-process thread pool to be deleted, before
643 643
  # any/all of the .deliver_later emails are processed
644 644
  def self.with_synched_deliveries(&block)
645
    adapter = ActionMailer::DeliveryJob.queue_adapter
645
    adapter = ActionMailer::MailDeliveryJob.queue_adapter
646 646
    if adapter.is_a?(ActiveJob::QueueAdapters::AsyncAdapter)
647
      ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
647
      ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
648 648
    end
649 649
    yield
650 650
  ensure
651
    ActionMailer::DeliveryJob.queue_adapter = adapter
651
    ActionMailer::MailDeliveryJob.queue_adapter = adapter
652 652
  end
653 653

  
654 654
  def mail(headers={}, &block)
config/application.rb
33 33
    config.active_record.store_full_sti_class = true
34 34
    config.active_record.default_timezone = :local
35 35

  
36
    config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
37

  
36 38
    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
37 39
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
38 40
    # config.time_zone = 'Central Time (US & Canada)'
lib/redmine/info.rb
16 16
          ["Rails version", Rails::VERSION::STRING],
17 17
          ["Environment", Rails.env],
18 18
          ["Database adapter", ActiveRecord::Base.connection.adapter_name],
19
          ["Mailer queue", ActionMailer::DeliveryJob.queue_adapter.class.name],
19
          ["Mailer queue", ActionMailer::MailDeliveryJob.queue_adapter.class.name],
20 20
          ["Mailer delivery", ActionMailer::Base.delivery_method]
21 21
        ].map {|info| "  %-30s %s" % info}.join("\n") + "\n"
22 22

  
test/unit/mailer_test.rb
1064 1064
  end
1065 1065

  
1066 1066
  def test_with_synched_deliveries_should_yield_with_synced_deliveries
1067
    ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new
1067
    ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new
1068 1068

  
1069 1069
    Mailer.with_synched_deliveries do
1070
      assert_kind_of ActiveJob::QueueAdapters::InlineAdapter, ActionMailer::DeliveryJob.queue_adapter
1070
      assert_kind_of ActiveJob::QueueAdapters::InlineAdapter, ActionMailer::MailDeliveryJob.queue_adapter
1071 1071
    end
1072
    assert_kind_of ActiveJob::QueueAdapters::AsyncAdapter, ActionMailer::DeliveryJob.queue_adapter
1072
    assert_kind_of ActiveJob::QueueAdapters::AsyncAdapter, ActionMailer::MailDeliveryJob.queue_adapter
1073 1073
  ensure
1074
    ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
1074
    ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
1075 1075
  end
1076 1076

  
1077 1077
  def test_email_addresses_should_keep_addresses
(9-9/21)