Improve CampaignCreateJob
This commit is contained in:
parent
9c9033f2d3
commit
ef9c4776fa
6 changed files with 16 additions and 20 deletions
13
app/jobs/campaign_create_job.rb
Normal file
13
app/jobs/campaign_create_job.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in a new issue