diff --git a/app/jobs/recurring_donation_change_amount_donor_email_job.rb b/app/jobs/recurring_donation_change_amount_donor_email_job.rb new file mode 100644 index 00000000..c97615ad --- /dev/null +++ b/app/jobs/recurring_donation_change_amount_donor_email_job.rb @@ -0,0 +1,7 @@ +class RecurringDonationChangeAmountDonorEmailJob < ApplicationJob + queue_as :default + + def perform(recurring_donation, previous_amount) + DonationMailer.donor_recurring_donation_change_amount(recurring_donation.id, previous_amount).deliver_now + end +end diff --git a/app/jobs/recurring_donation_change_amount_job.rb b/app/jobs/recurring_donation_change_amount_job.rb new file mode 100644 index 00000000..e28b4e2c --- /dev/null +++ b/app/jobs/recurring_donation_change_amount_job.rb @@ -0,0 +1,8 @@ +class RecurringDonationChangeAmountJob < ApplicationJob + queue_as :default + + def perform(recurring_donation, previous_amount) + RecurringDonationChangeAmountDonorEmailJob.perform_later(recurring_donation, previous_amount) + RecurringDonationChangeAmountNonprofitEmailJob.perform_later(recurring_donation, previous_amount) + end +end diff --git a/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb b/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb new file mode 100644 index 00000000..1250b63e --- /dev/null +++ b/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb @@ -0,0 +1,7 @@ +class RecurringDonationChangeAmountNonprofitEmailJob < ApplicationJob + queue_as :default + + def perform(*args) + # Do something later + end +end diff --git a/lib/job_types/donor_recurring_donation_change_amount_job.rb b/lib/job_types/donor_recurring_donation_change_amount_job.rb deleted file mode 100644 index 6fa6de5b..00000000 --- a/lib/job_types/donor_recurring_donation_change_amount_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -module JobTypes - class DonorRecurringDonationChangeAmountJob < EmailJob - attr_reader :donation_id, :previous_amount - def initialize(donation_id, previous_amount = nil) - @donation_id = donation_id - @previous_amount = previous_amount - end - - def perform - DonationMailer.donor_recurring_donation_change_amount(@donation_id, @previous_amount).deliver - end - end -end diff --git a/lib/update/update_recurring_donations.rb b/lib/update/update_recurring_donations.rb index 2047b304..cbd05b5e 100644 --- a/lib/update/update_recurring_donations.rb +++ b/lib/update/update_recurring_donations.rb @@ -73,8 +73,8 @@ module UpdateRecurringDonations rd.save! donation.save! end + RecurringDonationChangeAmountJob.perform_later(rd, previous_amount) EmailJobQueue.queue(JobTypes::NonprofitRecurringDonationChangeAmountJob, rd.id, previous_amount) - EmailJobQueue.queue(JobTypes::DonorRecurringDonationChangeAmountJob, rd.id, previous_amount) rd end diff --git a/spec/lib/job_types/donor_recurring_donation_change_amount_job_spec.rb b/spec/lib/job_types/donor_recurring_donation_change_amount_job_spec.rb deleted file mode 100644 index e0d953f7..00000000 --- a/spec/lib/job_types/donor_recurring_donation_change_amount_job_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -require 'rails_helper.rb' - -describe JobTypes::DonorRecurringDonationChangeAmountJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(DonationMailer).to receive(:donor_recurring_donation_change_amount).with(1, 100).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::DonorRecurringDonationChangeAmountJob.new(1, 100) - job.perform - end - end -end diff --git a/spec/lib/update/update_recurring_donations_spec.rb b/spec/lib/update/update_recurring_donations_spec.rb index 9c0f600d..a79fbee8 100644 --- a/spec/lib/update/update_recurring_donations_spec.rb +++ b/spec/lib/update/update_recurring_donations_spec.rb @@ -93,10 +93,13 @@ describe UpdateRecurringDonations do orig_rd = recurring_donation.attributes.with_indifferent_access orig_donation = recurring_donation.donation.attributes.with_indifferent_access - expect_email_queued.with(JobTypes::DonorRecurringDonationChangeAmountJob, recurring_donation.id, orig_rd['amount']) expect_email_queued.with(JobTypes::NonprofitRecurringDonationChangeAmountJob, recurring_donation.id, orig_rd['amount']) - result = UpdateRecurringDonations.update_amount(recurring_donation, source_token.token, 1000) + result = nil + expect { + result = UpdateRecurringDonations.update_amount(recurring_donation, + source_token.token, 1000) + }.to have_enqueue_with(RecurringDonationChangeAmountJob).with(recurring_donation, orig_rd['amount']) expectations = { donation: orig_donation.merge(amount: 1000, card_id: source_token.tokenizable.id),