diff --git a/app/jobs/campaign_create_job.rb b/app/jobs/campaign_create_job.rb new file mode 100644 index 00000000..d166f2f3 --- /dev/null +++ b/app/jobs/campaign_create_job.rb @@ -0,0 +1,13 @@ +class CampaignCreateJob < ApplicationJob + queue_as :default + + def perform(campaign) + if campaign.child_campaign? + CampaignMailer.federated_creation_followup(campaign).deliver_later + else + CampaignMailer.creation_followup(campaign).deliver_later + end + + FundraiserCreateJob.perform_later(campaign) + end +end diff --git a/app/jobs/supporter_fundraiser_create_job.rb b/app/jobs/supporter_fundraiser_create_job.rb index 18a42955..262f277f 100644 --- a/app/jobs/supporter_fundraiser_create_job.rb +++ b/app/jobs/supporter_fundraiser_create_job.rb @@ -2,6 +2,6 @@ class SupporterFundraiserCreateJob < ApplicationJob queue_as :default def perform(fundraiser) - NonprofitAdminMailer.supporter_fundraiser(fundraiser).deliver_now + NonprofitAdminMailer.supporter_fundraiser(fundraiser).deliver_now unless QueryRoles.is_nonprofit_user?(fundraiser.profile.user.id, fundraiser.nonprofit.id) end end diff --git a/app/models/campaign.rb b/app/models/campaign.rb index 8bef17e7..e60cdd82 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -99,12 +99,7 @@ class Campaign < ApplicationRecord after_create do user = profile.user Role.create(name: :campaign_editor, user_id: user.id, host: self) - if child_campaign? - CampaignMailer.delay.federated_creation_followup(self) - else - CampaignMailer.delay.creation_followup(self) - end - + CampaignCreateJob.perform_later(self) 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 62a8e177..973ed6d1 100644 --- a/lib/create/create_campaign.rb +++ b/lib/create/create_campaign.rb @@ -16,7 +16,7 @@ module CreateCampaign # do notifications user = campaign.profile.user Role.create(name: :campaign_editor, user_id: user.id, host: self) - CampaignMailer.delay.creation_followup(self) + CampaignCreateJob.perform_later(self) 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/spec/lib/create/create_campaign_gift_spec.rb b/spec/lib/create/create_campaign_gift_spec.rb index 72774284..a33f52a6 100644 --- a/spec/lib/create/create_campaign_gift_spec.rb +++ b/spec/lib/create/create_campaign_gift_spec.rb @@ -5,12 +5,6 @@ require 'rails_helper' describe CreateCampaignGift do describe '.create' do - before(:each) do - # #stub out the mailing stuff used by campaign creation - cm = double(CampaignMailer) - allow(cm).to receive(:creation_followup) - allow(CampaignMailer).to receive(:delay).and_return(cm) - end describe 'param validation' do let (:donation) { force_create(:donation) } it 'basic validation' do diff --git a/spec/lib/delete/delete_campaign_gift_option_spec.rb b/spec/lib/delete/delete_campaign_gift_option_spec.rb index 8f47828d..1274faad 100644 --- a/spec/lib/delete/delete_campaign_gift_option_spec.rb +++ b/spec/lib/delete/delete_campaign_gift_option_spec.rb @@ -4,12 +4,6 @@ require 'rails_helper' describe DeleteCampaignGiftOption do - before(:each) do - # #stub out the mailing stuff used by campaign creation - cm = double(CampaignMailer) - allow(cm).to receive(:creation_followup) - allow(CampaignMailer).to receive(:delay).and_return(cm) - end describe '.delete' do let(:profile) { force_create(:profile, user: force_create(:user)) } let(:campaign) { force_create(:campaign, profile: profile) }