From b2aaf30a140f560f13be7bc7b18771339710c150 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 7 Nov 2019 13:40:17 -0600 Subject: [PATCH] Add SupporterFundraiserCreateJob --- app/jobs/supporter_fundraiser_create_job.rb | 7 +++++++ app/models/campaign.rb | 2 +- lib/create/create_campaign.rb | 2 +- .../nonprofit_admin_supporter_fundraiser_job.rb | 16 ---------------- spec/lib/create/create_campaign_gift_spec.rb | 3 --- .../delete/delete_campaign_gift_option_spec.rb | 3 --- ...profit_admin_supporter_fundraiser_job_spec.rb | 15 --------------- 7 files changed, 9 insertions(+), 39 deletions(-) create mode 100644 app/jobs/supporter_fundraiser_create_job.rb delete mode 100644 lib/job_types/nonprofit_admin_supporter_fundraiser_job.rb delete mode 100644 spec/lib/job_types/nonprofit_admin_supporter_fundraiser_job_spec.rb diff --git a/app/jobs/supporter_fundraiser_create_job.rb b/app/jobs/supporter_fundraiser_create_job.rb new file mode 100644 index 00000000..18a42955 --- /dev/null +++ b/app/jobs/supporter_fundraiser_create_job.rb @@ -0,0 +1,7 @@ +class SupporterFundraiserCreateJob < ApplicationJob + queue_as :default + + def perform(fundraiser) + NonprofitAdminMailer.supporter_fundraiser(fundraiser).deliver_now + end +end diff --git a/app/models/campaign.rb b/app/models/campaign.rb index 09791bcf..8bef17e7 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -105,7 +105,7 @@ class Campaign < ApplicationRecord CampaignMailer.delay.creation_followup(self) end - NonprofitAdminMailer.delay.supporter_fundraiser(self) unless QueryRoles.is_nonprofit_user?(user.id, nonprofit_id) + SupporterFundraiserCreateJob.perform_later(self) unless QueryRoles.is_nonprofit_user?(user.id, nonprofit_id) self end diff --git a/lib/create/create_campaign.rb b/lib/create/create_campaign.rb index 4a7f854c..62a8e177 100644 --- a/lib/create/create_campaign.rb +++ b/lib/create/create_campaign.rb @@ -17,7 +17,7 @@ module CreateCampaign user = campaign.profile.user Role.create(name: :campaign_editor, user_id: user.id, host: self) CampaignMailer.delay.creation_followup(self) - NonprofitAdminMailer.delay.supporter_fundraiser(self) unless QueryRoles.is_nonprofit_user?(user.id, nonprofit_id) + SupporterFundraiserCreateJob.perform_later(self) unless QueryRoles.is_nonprofit_user?(user.id, nonprofit_id) return { errors: campaign.errors.messages }.as_json unless campaign.errors.empty? diff --git a/lib/job_types/nonprofit_admin_supporter_fundraiser_job.rb b/lib/job_types/nonprofit_admin_supporter_fundraiser_job.rb deleted file mode 100644 index a4a2937d..00000000 --- a/lib/job_types/nonprofit_admin_supporter_fundraiser_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 NonprofitAdminSupporterFundraiserJob < EmailJob - attr_reader :event_or_campaign - - def initialize(event_or_campaign) - @event_or_campaign = event_or_campaign - end - - def perform - NonprofitAdminMailer.supporter_fundraiser(@event_or_campaign).deliver - end - end -end diff --git a/spec/lib/create/create_campaign_gift_spec.rb b/spec/lib/create/create_campaign_gift_spec.rb index 49b806ad..72774284 100644 --- a/spec/lib/create/create_campaign_gift_spec.rb +++ b/spec/lib/create/create_campaign_gift_spec.rb @@ -9,10 +9,7 @@ describe CreateCampaignGift do # #stub out the mailing stuff used by campaign creation cm = double(CampaignMailer) allow(cm).to receive(:creation_followup) - nam = double(NonprofitAdminMailer) - allow(nam).to receive(:supporter_fundraiser) allow(CampaignMailer).to receive(:delay).and_return(cm) - allow(NonprofitAdminMailer).to receive(:delay).and_return(nam) end describe 'param validation' do let (:donation) { force_create(:donation) } diff --git a/spec/lib/delete/delete_campaign_gift_option_spec.rb b/spec/lib/delete/delete_campaign_gift_option_spec.rb index fdb5ee2b..8f47828d 100644 --- a/spec/lib/delete/delete_campaign_gift_option_spec.rb +++ b/spec/lib/delete/delete_campaign_gift_option_spec.rb @@ -8,10 +8,7 @@ describe DeleteCampaignGiftOption do # #stub out the mailing stuff used by campaign creation cm = double(CampaignMailer) allow(cm).to receive(:creation_followup) - nam = double(NonprofitAdminMailer) - allow(nam).to receive(:supporter_fundraiser) allow(CampaignMailer).to receive(:delay).and_return(cm) - allow(NonprofitAdminMailer).to receive(:delay).and_return(nam) end describe '.delete' do let(:profile) { force_create(:profile, user: force_create(:user)) } diff --git a/spec/lib/job_types/nonprofit_admin_supporter_fundraiser_job_spec.rb b/spec/lib/job_types/nonprofit_admin_supporter_fundraiser_job_spec.rb deleted file mode 100644 index dacfd115..00000000 --- a/spec/lib/job_types/nonprofit_admin_supporter_fundraiser_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::NonprofitAdminSupporterFundraiserJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(NonprofitAdminMailer).to receive(:supporter_fundraiser).with(1).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::NonprofitAdminSupporterFundraiserJob.new(1) - job.perform - end - end -end