diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-10-06 16:07:45 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-10-06 16:07:45 +0000 |
commit | 5533eeff239e024539f3ddd5b2ffe3528144beef (patch) | |
tree | 6e9db37cec7f40489946649469bf531b268035a8 | |
parent | e159928e6b81c02001411e7e886208533178c0ba (diff) | |
download | redmine-5533eeff239e024539f3ddd5b2ffe3528144beef.tar.gz redmine-5533eeff239e024539f3ddd5b2ffe3528144beef.zip |
Fixed that test_email raises an error with #deliver_later (#26791).
git-svn-id: http://svn.redmine.org/redmine/trunk@17587 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/mailer.rb | 45 | ||||
-rw-r--r-- | config/environments/test.rb | 3 | ||||
-rw-r--r-- | test/unit/mailer_test.rb | 6 |
3 files changed, 13 insertions, 41 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb index ab1a6cf4c..8f4262950 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -107,48 +107,11 @@ class Mailer < ActionMailer::Base "method*, or 3. use a custom Active Job instead of #deliver_later." else args = 'Mailer', @action.to_s, delivery_method.to_s, *@args - DeliveryJob.set(options).perform_later(*args) + ::ActionMailer::DeliveryJob.set(options).perform_later(*args) end end end - class DeliveryJob < ActionMailer::DeliveryJob - module Arguments - extend ActiveJob::Arguments - extend self - - private - - def serialize_argument(argument) - # Ensure that ActiveRecord::Base objects are fully serialized for mail - # sending. This circumvents the globalid gem for this job. - if argument.is_a?(ActiveRecord::Base) - argument.to_yaml - else - super - end - end - - def deserialize_argument(argument) - if argument.is_a?(ActiveRecord::Base) - argument - else - super - end - end - end - - private - - def serialize_arguments(serialized_args) - Arguments.serialize(serialized_args) - end - - def deserialize_arguments(serialized_args) - Arguments.deserialize(serialized_args) - end - end - def process(action, *args) user = args.shift raise ArgumentError, "First argument has to be a user, was #{user.inspect}" unless user.is_a?(User) @@ -701,9 +664,9 @@ class Mailer < ActionMailer::Base # # Example: # test_email => Mail::Message object - def test_email + def test_email(user) @url = url_for(:controller => 'welcome') - mail :to => User.current.mail, + mail :to => user.mail, :subject => 'Redmine test' end @@ -712,7 +675,7 @@ class Mailer < ActionMailer::Base # Example: # Mailer.test_email(user).deliver => send an email to the given user def self.test_email(user) - MultiMessage.new(:test_email).for(user) + MultiMessage.new(:test_email, user).for(user) end # Sends reminders to issue assignees diff --git a/config/environments/test.rb b/config/environments/test.rb index 645996dce..e1a3252b0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -22,6 +22,9 @@ Rails.application.configure do # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + + # Disable Async delivery + config.active_job.queue_adapter = :inline # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 0908e9e63..5d2ac0d31 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -605,6 +605,12 @@ class MailerTest < ActiveSupport::TestCase end end + def test_test_email_later + user = User.find(1) + assert Mailer.test_email(user).deliver_later + assert_equal 1, ActionMailer::Base.deliveries.size + end + def test_reminders Mailer.reminders(:days => 42) assert_equal 1, ActionMailer::Base.deliveries.size |