diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 3fb09b3a9a6..458d28ce9cb 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -45,15 +45,6 @@ class ApplicationMailer < ActionMailer::Base default from: Proc.new { Setting.mail_from } class << self - # Activates/deactivates email deliveries during +block+ - def with_deliveries(temporary_state = true, &) - old_state = ActionMailer::Base.perform_deliveries - ActionMailer::Base.perform_deliveries = temporary_state - yield - ensure - ActionMailer::Base.perform_deliveries = old_state - end - def host if OpenProject::Configuration.rails_relative_url_root.blank? Setting.host_name diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb index 7209ea10c34..76caa2d6817 100644 --- a/app/workers/copy_project_job.rb +++ b/app/workers/copy_project_job.rb @@ -112,20 +112,16 @@ class CopyProjectJob < ApplicationJob # rubocop:disable Metrics/AbcSize # Most of the cost is from handling errors, we need to check what can be moved around / removed def create_project_copy(target_project_params, associations_to_copy, send_mails) - errors = [] + service_result = copy_project(target_project_params, associations_to_copy, send_mails) + target_project = service_result.result + errors = service_result.errors.full_messages - ProjectMailer.with_deliveries(send_mails) do - service_result = copy_project(target_project_params, associations_to_copy, send_mails) - target_project = service_result.result - errors = service_result.errors.full_messages - - # We assume the copying worked "successfully" if the project was saved - if target_project&.persisted? - return target_project, errors - else - logger.error("Copying project fails with validation errors: #{errors.join("\n")}") - return nil, errors - end + # We assume the copying worked "successfully" if the project was saved + if target_project&.persisted? + [target_project, errors] + else + logger.error("Copying project fails with validation errors: #{errors.join("\n")}") + [nil, errors] end rescue ActiveRecord::RecordNotFound => e logger.error("Entity missing: #{e.message} #{e.backtrace.join("\n")}") diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index eaf89b6c55a..8171c09860f 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -69,40 +69,6 @@ RSpec.describe UserMailer do allow(Setting).to receive(:default_language).and_return("en") end - describe "#with_deliveries" do - context "with false" do - before do - described_class.with_deliveries(false) do - described_class.test_mail(recipient).deliver_now - end - end - - it_behaves_like "mail is not sent" - end - - context "with true" do - before do - described_class.with_deliveries(true) do - described_class.test_mail(recipient).deliver_now - end - end - - it_behaves_like "mail is sent" - end - - context "with true but user is locked" do - let(:recipient) { build_stubbed(:user, status: Principal.statuses[:locked]) } - - before do - described_class.with_deliveries(true) do - described_class.test_mail(recipient).deliver_now - end - end - - it_behaves_like "mail is not sent" - end - end - describe "#test_mail" do let(:test_email) { "bob.bobbi@example.com" } let(:recipient) { build_stubbed(:user, firstname: "Bob", lastname: "Bobbi", mail: test_email) }