OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
get rid of with_deliveries method
Ivan Kuchind7aec46d9fb8
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rbindex 3fb09b3a9a6..458d28ce9cb 100644--- a/app/mailers/application_mailer.rb+++ b/app/mailers/application_mailer.rb@@ -45,15 +45,6 @@ class ApplicationMailer < ActionMailer::Basedefault 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 hostif OpenProject::Configuration.rails_relative_url_root.blank?Setting.host_namediff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rbindex 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 / removeddef create_project_copy(target_project_params, associations_to_copy, send_mails)- errors = []-- 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+ 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?+ [target_project, errors]+ else+ logger.error("Copying project fails with validation errors: #{errors.join("\n")}")+ [nil, errors]endrescue ActiveRecord::RecordNotFound => elogger.error("Entity missing: #{e.message} #{e.backtrace.join("\n")}")diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rbindex eaf89b6c55a..8171c09860f 100644--- a/spec/mailers/user_mailer_spec.rb+++ b/spec/mailers/user_mailer_spec.rb@@ -69,40 +69,6 @@ RSpec.describe UserMailer doallow(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" dolet(:test_email) { "[email protected]" }let(:recipient) { build_stubbed(:user, firstname: "Bob", lastname: "Bobbi", mail: test_email) }