From f68a432ee5f76a74883aa45009b348ca77cc3467 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 7 Nov 2019 13:03:04 -0600 Subject: [PATCH] Add NonprofitCreateJob --- app/jobs/nonprofit_create_job.rb | 7 +++++++ lib/job_types/nonprofit_welcome_job.rb | 16 ---------------- lib/onboard_accounts.rb | 2 +- spec/lib/job_types/nonprofit_welcome_job_spec.rb | 15 --------------- 4 files changed, 8 insertions(+), 32 deletions(-) create mode 100644 app/jobs/nonprofit_create_job.rb delete mode 100644 lib/job_types/nonprofit_welcome_job.rb delete mode 100644 spec/lib/job_types/nonprofit_welcome_job_spec.rb diff --git a/app/jobs/nonprofit_create_job.rb b/app/jobs/nonprofit_create_job.rb new file mode 100644 index 00000000..98ee7a11 --- /dev/null +++ b/app/jobs/nonprofit_create_job.rb @@ -0,0 +1,7 @@ +class NonprofitCreateJob < ApplicationJob + queue_as :default + + def perform(nonprofit) + NonprofitMailer.welcome(nonprofit.id).deliver + end +end diff --git a/lib/job_types/nonprofit_welcome_job.rb b/lib/job_types/nonprofit_welcome_job.rb deleted file mode 100644 index 8c13bdb1..00000000 --- a/lib/job_types/nonprofit_welcome_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 NonprofitWelcomeJob < EmailJob - attr_reader :nonprofit_id - - def initialize(nonprofit_id) - @nonprofit_id = nonprofit_id - end - - def perform - NonprofitMailer.welcome(@nonprofit_id).deliver - end - end -end diff --git a/lib/onboard_accounts.rb b/lib/onboard_accounts.rb index 38e944c4..156b2ca7 100644 --- a/lib/onboard_accounts.rb +++ b/lib/onboard_accounts.rb @@ -124,7 +124,7 @@ module OnboardAccounts # user_data and extra_info are additional data hashes sent from the onboarding form def self.send_onboard_email(np, nonprofit_data, user_data, extra_info) # Send the welcome email to the nonprofit - NonprofitMailer.welcome(np['id']).deliver + NonprofitCreateJob.perform_later(Nonprofit.find(np['id'])) # Send an email notifying people internal folks of the new nonporfit, with the above info and extra_info to_emails = ['support@commitchange.com'] message = %( diff --git a/spec/lib/job_types/nonprofit_welcome_job_spec.rb b/spec/lib/job_types/nonprofit_welcome_job_spec.rb deleted file mode 100644 index c5099ead..00000000 --- a/spec/lib/job_types/nonprofit_welcome_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::NonprofitWelcomeJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(NonprofitMailer).to receive(:welcome).with(1).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::NonprofitWelcomeJob.new(1) - job.perform - end - end -end