Use AdminFailedGiftJob
This commit is contained in:
parent
ef9c4776fa
commit
34e67f5577
3 changed files with 22 additions and 27 deletions
|
@ -86,7 +86,7 @@ class Event < ApplicationRecord
|
||||||
after_create do
|
after_create do
|
||||||
user = profile.user
|
user = profile.user
|
||||||
Role.create(name: :event_editor, user_id: user.id, host: self)
|
Role.create(name: :event_editor, user_id: user.id, host: self)
|
||||||
EventMailer.delay.creation_followup(self)
|
EventCreateJob.perform_later self
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,12 @@ module CreateCampaignGift
|
||||||
if !donation.recurring_donation.nil? && (!campaign_gift_option.amount_recurring.nil? && campaign_gift_option.amount_recurring > 0)
|
if !donation.recurring_donation.nil? && (!campaign_gift_option.amount_recurring.nil? && campaign_gift_option.amount_recurring > 0)
|
||||||
# it's a recurring_donation. Is it enough? for the gift level?
|
# it's a recurring_donation. Is it enough? for the gift level?
|
||||||
unless donation.recurring_donation.amount == campaign_gift_option.amount_recurring
|
unless donation.recurring_donation.amount == campaign_gift_option.amount_recurring
|
||||||
AdminMailer.delay.notify_failed_gift(donation, campaign_gift_option)
|
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
|
||||||
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} gift options requires a recurring donation of #{campaign_gift_option.amount_recurring} for donation #{donation.id}", key: :campaign_gift_option_id)
|
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} gift options requires a recurring donation of #{campaign_gift_option.amount_recurring} for donation #{donation.id}", key: :campaign_gift_option_id)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
unless donation.amount == campaign_gift_option.amount_one_time
|
unless donation.amount == campaign_gift_option.amount_one_time
|
||||||
AdminMailer.delay.notify_failed_gift(donation, campaign_gift_option)
|
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
|
||||||
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} gift options requires a donation of #{campaign_gift_option.amount_one_time} for donation #{donation.id}", key: :campaign_gift_option_id)
|
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} gift options requires a donation of #{campaign_gift_option.amount_one_time} for donation #{donation.id}", key: :campaign_gift_option_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,7 +56,7 @@ module CreateCampaignGift
|
||||||
return gift
|
return gift
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
AdminMailer.delay.notify_failed_gift(donation, campaign_gift_option)
|
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
|
||||||
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} has no more inventory", key: :campaign_gift_option_id)
|
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} has no more inventory", key: :campaign_gift_option_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -78,53 +78,48 @@ describe CreateCampaignGift do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects associations when the donation amount is too low' do
|
it 'rejects associations when the donation amount is too low' do
|
||||||
adm = double(AdminMailer)
|
|
||||||
|
|
||||||
donation = force_create(:donation, campaign: campaign, amount: 299)
|
donation = force_create(:donation, campaign: campaign, amount: 299)
|
||||||
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_one_time: 300, name: 'name')
|
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_one_time: 300, name: 'name')
|
||||||
expect(adm).to receive(:notify_failed_gift).with(donation, campaign_gift_option)
|
expect {
|
||||||
expect(AdminMailer).to receive(:delay).and_return(adm)
|
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
|
||||||
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
|
expect(error).to be_a(ParamValidation::ValidationError)
|
||||||
expect(error).to be_a(ParamValidation::ValidationError)
|
expect_validation_errors(error.data, key: :campaign_gift_option_id)
|
||||||
expect_validation_errors(error.data, key: :campaign_gift_option_id)
|
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a donation of 300 for donation #{donation.id}"
|
||||||
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a donation of 300 for donation #{donation.id}"
|
}
|
||||||
}
|
}.to have_enqueued_job(AdminFailedGiftJob).with(donation,campaign_gift_option)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects associations when the recurring donation amount is too low' do
|
it 'rejects associations when the recurring donation amount is too low' do
|
||||||
adm = double(AdminMailer)
|
|
||||||
|
|
||||||
donation = force_create(:donation, campaign: campaign, amount: 299, recurring: true)
|
donation = force_create(:donation, campaign: campaign, amount: 299, recurring: true)
|
||||||
rd = force_create(:recurring_donation, amount: 299, donation: donation)
|
rd = force_create(:recurring_donation, amount: 299, donation: donation)
|
||||||
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_recurring: 300, name: 'name')
|
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_recurring: 300, name: 'name')
|
||||||
|
|
||||||
expect(adm).to receive(:notify_failed_gift).with(donation, campaign_gift_option)
|
expect {
|
||||||
expect(AdminMailer).to receive(:delay).and_return(adm)
|
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
|
||||||
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
|
|
||||||
expect(error).to be_a(ParamValidation::ValidationError)
|
expect(error).to be_a(ParamValidation::ValidationError)
|
||||||
expect_validation_errors(error.data, key: :campaign_gift_option_id)
|
expect_validation_errors(error.data, key: :campaign_gift_option_id)
|
||||||
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a recurring donation of 300 for donation #{donation.id}"
|
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a recurring donation of 300 for donation #{donation.id}"
|
||||||
}
|
}
|
||||||
|
}.to have_enqueued_job(AdminFailedGiftJob).with(donation,campaign_gift_option)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects association when the there are no gifts available' do
|
it 'rejects association when the there are no gifts available' do
|
||||||
adm = double(AdminMailer)
|
|
||||||
|
|
||||||
donation = force_create(:donation, campaign: campaign, amount: 300, recurring: true)
|
donation = force_create(:donation, campaign: campaign, amount: 300, recurring: true)
|
||||||
rd = force_create(:recurring_donation, amount: 300, donation: donation)
|
rd = force_create(:recurring_donation, amount: 300, donation: donation)
|
||||||
|
|
||||||
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_recurring: 300, quantity: 1)
|
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_recurring: 300, quantity: 1)
|
||||||
expect(adm).to receive(:notify_failed_gift).with(donation, campaign_gift_option)
|
|
||||||
expect(AdminMailer).to receive(:delay).and_return(adm)
|
|
||||||
|
|
||||||
campaign_gift = force_create(:campaign_gift, campaign_gift_option: campaign_gift_option)
|
campaign_gift = force_create(:campaign_gift, campaign_gift_option: campaign_gift_option)
|
||||||
|
|
||||||
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
|
expect {
|
||||||
expect(error).to be_a(ParamValidation::ValidationError)
|
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
|
||||||
expect_validation_errors(error.data, [{ key: :campaign_gift_option_id }])
|
expect(error).to be_a(ParamValidation::ValidationError)
|
||||||
expect(error.message).to eq "#{campaign_gift_option.id} has no more inventory"
|
expect_validation_errors(error.data, [{ key: :campaign_gift_option_id }])
|
||||||
expect(CampaignGift.count).to eq 1
|
expect(error.message).to eq "#{campaign_gift_option.id} has no more inventory"
|
||||||
}
|
expect(CampaignGift.count).to eq 1
|
||||||
|
}
|
||||||
|
}.to have_enqueued_job(AdminFailedGiftJob).with(donation,campaign_gift_option)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue