diff --git a/app/jobs/role_added_job.rb b/app/jobs/role_added_job.rb new file mode 100644 index 00000000..fc9b0401 --- /dev/null +++ b/app/jobs/role_added_job.rb @@ -0,0 +1,7 @@ +class RoleAddedJob < ApplicationJob + queue_as :default + + def perform(role) + NonprofitAdminMailer.existing_invite(role).deliver_now + end +end diff --git a/app/models/role.rb b/app/models/role.rb index c118956a..67108d88 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -47,7 +47,7 @@ end return role unless role.valid? if user.confirmed? - NonprofitAdminMailer.delay.existing_invite(role) + RoleAddedJob.perform_later role else NonprofitAdminMailer.delay.new_invite(role, user.make_confirmation_token!) end diff --git a/lib/job_types/nonprofit_admin_existing_invite_job.rb b/lib/job_types/nonprofit_admin_existing_invite_job.rb deleted file mode 100644 index 0eae9123..00000000 --- a/lib/job_types/nonprofit_admin_existing_invite_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 NonprofitAdminExistingInviteJob < EmailJob - attr_reader :role - - def initialize(role) - @role = role - end - - def perform - NonprofitAdminMailer.existing_invite(@role).deliver - end - end -end diff --git a/spec/lib/job_types/nonprofit_admin_existing_invite_job_spec.rb b/spec/lib/job_types/nonprofit_admin_existing_invite_job_spec.rb deleted file mode 100644 index 47147e8d..00000000 --- a/spec/lib/job_types/nonprofit_admin_existing_invite_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::NonprofitAdminExistingInviteJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(NonprofitAdminMailer).to receive(:existing_invite).with(1).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::NonprofitAdminExistingInviteJob.new(1) - job.perform - end - end -end