[22158] Fix CopyProjectJob notifications

* Actually send copy job notifications

* Skip enqueuing notifications when mails are disabled

Aggregated journal notifications are sent after a delay, after which the
actual job has long completed.
pull/4301/head
Oliver Günther 9 years ago
parent d6413d18c6
commit 9db305439d
  1. 4
      app/mailers/user_mailer.rb
  2. 1
      app/models/journal_notification_mailer.rb
  3. 4
      app/workers/copy_project_job.rb
  4. 10
      spec/controllers/copy_projects_controller_spec.rb
  5. 13
      spec/models/copy_project_job_spec.rb

@ -343,12 +343,12 @@ class UserMailer < BaseMailer
def mail_for_author(author, headers = {}, &block) def mail_for_author(author, headers = {}, &block)
message = mail headers, &block message = mail headers, &block
remove_self_notifications(message, author) self.class.remove_self_notifications(message, author)
message message
end end
def remove_self_notifications(message, author) def self.remove_self_notifications(message, author)
if author.pref && author.pref[:no_self_notified] if author.pref && author.pref[:no_self_notified]
message.to = message.to.reject { |address| address == author.mail } if message.to.present? message.to = message.to.reject { |address| address == author.mail } if message.to.present?
end end

@ -39,6 +39,7 @@ class JournalNotificationMailer
def handle_work_package_journal(journal) def handle_work_package_journal(journal)
return nil unless send_notification? journal return nil unless send_notification? journal
return nil unless ::UserMailer.perform_deliveries
aggregated = find_aggregated_journal_for(journal) aggregated = find_aggregated_journal_for(journal)

@ -60,11 +60,11 @@ class CopyProjectJob
} }
if target_project if target_project
UserMailer.copy_project_succeeded(user, source_project, target_project, errors) UserMailer.copy_project_succeeded(user, source_project, target_project, errors).deliver_now
else else
target_project_name = target_project_params[:name] target_project_name = target_project_params[:name]
UserMailer.copy_project_failed(user, source_project, target_project_name) UserMailer.copy_project_failed(user, source_project, target_project_name).deliver_now
end end
end end

@ -141,9 +141,15 @@ describe CopyProjectsController, type: :controller do
end end
describe 'copy sends eMail' do describe 'copy sends eMail' do
let(:maildouble) { double('Mail::Message', deliver: true) }
before do
allow(maildouble).to receive(:deliver_now).and_return nil
end
context 'on success' do context 'on success' do
it 'user receives success mail' do it 'user receives success mail' do
expect(UserMailer).to receive(:copy_project_succeeded).and_return(double('mailer', deliver: true)) expect(UserMailer).to receive(:copy_project_succeeded).and_return(maildouble)
copy_project(project) copy_project(project)
end end
@ -155,7 +161,7 @@ describe CopyProjectsController, type: :controller do
end end
it 'user receives success mail' do it 'user receives success mail' do
expect(UserMailer).to receive(:copy_project_failed).and_return(double('mailer', deliver: true)) expect(UserMailer).to receive(:copy_project_failed).and_return(maildouble)
copy_project(project) copy_project(project)
end end

@ -33,6 +33,11 @@ describe CopyProjectJob, type: :model do
let(:user) { FactoryGirl.create(:user) } let(:user) { FactoryGirl.create(:user) }
let(:role) { FactoryGirl.create(:role, permissions: [:copy_projects]) } let(:role) { FactoryGirl.create(:role, permissions: [:copy_projects]) }
let(:params) { { name: 'Copy', identifier: 'copy' } } let(:params) { { name: 'Copy', identifier: 'copy' } }
let(:maildouble) { double('Mail::Message', deliver: true) }
before do
allow(maildouble).to receive(:deliver_now).and_return nil
end
describe 'copy localizes error message' do describe 'copy localizes error message' do
let(:user_de) { FactoryGirl.create(:admin, language: :de) } let(:user_de) { FactoryGirl.create(:admin, language: :de) }
@ -52,7 +57,7 @@ describe CopyProjectJob, type: :model do
# (see https://github.com/collectiveidea/delayed_job#rails-3-mailers). # (see https://github.com/collectiveidea/delayed_job#rails-3-mailers).
# Thus, we need to return a message object here, otherwise 'Delayed Job' # Thus, we need to return a message object here, otherwise 'Delayed Job'
# will complain about an object without a method #deliver. # will complain about an object without a method #deliver.
allow(UserMailer).to receive(:copy_project_failed).and_return(double('Mail::Message', deliver: true)) allow(UserMailer).to receive(:copy_project_failed).and_return(maildouble)
end end
it 'sets locale correctly' do it 'sets locale correctly' do
@ -97,7 +102,7 @@ describe CopyProjectJob, type: :model do
# (see https://github.com/collectiveidea/delayed_job#rails-3-mailers). # (see https://github.com/collectiveidea/delayed_job#rails-3-mailers).
# Thus, we need to return a message object here, otherwise 'Delayed Job' # Thus, we need to return a message object here, otherwise 'Delayed Job'
# will complain about an object without a method #deliver. # will complain about an object without a method #deliver.
allow(UserMailer).to receive(:copy_project_succeeded).and_return(double('Mail::Message', deliver: true)) allow(UserMailer).to receive(:copy_project_succeeded).and_return(maildouble)
@copied_project, @errors = copy_job.send(:create_project_copy, @copied_project, @errors = copy_job.send(:create_project_copy,
source_project, source_project,
@ -138,7 +143,7 @@ describe CopyProjectJob, type: :model do
let(:subproject) { FactoryGirl.create(:project, parent: project) } let(:subproject) { FactoryGirl.create(:project, parent: project) }
describe 'invalid parent' do describe 'invalid parent' do
before do expect(UserMailer).to receive(:copy_project_failed).and_return(double('mailer', deliver: true)) end before do expect(UserMailer).to receive(:copy_project_failed).and_return(maildouble) end
include_context 'copy project' do include_context 'copy project' do
let(:project_to_copy) { subproject } let(:project_to_copy) { subproject }
@ -157,7 +162,7 @@ describe CopyProjectJob, type: :model do
} }
before do before do
expect(UserMailer).to receive(:copy_project_succeeded).and_return(double('mailer', deliver: true)) expect(UserMailer).to receive(:copy_project_succeeded).and_return(maildouble)
member_add_subproject member_add_subproject
end end

Loading…
Cancel
Save