Improve CampaignCreateJob

This commit is contained in:
Eric Schultz 2019-11-07 15:27:37 -06:00
parent 9c9033f2d3
commit ef9c4776fa
6 changed files with 16 additions and 20 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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?

View file

@ -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

View file

@ -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) }