Merge pull request #6634 from Matt-Yorkley/jobs-cleanup

Jobs cleanup
This commit is contained in:
Pau Pérez Fabregat
2021-01-14 10:08:15 +01:00
committed by GitHub
11 changed files with 14 additions and 64 deletions

View File

@@ -35,7 +35,7 @@ module Admin
new_user.save!
@enterprise.users << new_user
ManagerInvitationJob.perform_later(@enterprise.id, new_user.id)
EnterpriseMailer.manager_invitation(@enterprise, new_user).deliver_later
new_user
end

View File

@@ -1,8 +0,0 @@
# frozen_string_literal: true
class ConfirmSignupJob < ActiveJob::Base
def perform(user_id)
user = Spree::User.find user_id
Spree::UserMailer.signup_confirmation(user).deliver_now
end
end

View File

@@ -1,9 +0,0 @@
# frozen_string_literal: true
class ManagerInvitationJob < ActiveJob::Base
def perform(enterprise_id, user_id)
enterprise = Enterprise.find enterprise_id
user = Spree::User.find user_id
EnterpriseMailer.manager_invitation(enterprise, user).deliver_now
end
end

View File

@@ -1,8 +0,0 @@
# frozen_string_literal: true
class WelcomeEnterpriseJob < ActiveJob::Base
def perform(enterprise_id)
enterprise = Enterprise.find enterprise_id
EnterpriseMailer.welcome(enterprise).deliver_now
end
end

View File

@@ -400,7 +400,7 @@ class Enterprise < ActiveRecord::Base
end
def send_welcome_email
WelcomeEnterpriseJob.perform_later(id)
EnterpriseMailer.welcome(self).deliver_later
end
def strip_url(url)

View File

@@ -101,7 +101,7 @@ module Spree
end
def send_signup_confirmation
ConfirmSignupJob.perform_later(id)
Spree::UserMailer.signup_confirmation(self).deliver_later
end
def associate_customers

View File

@@ -28,16 +28,17 @@ module Admin
end
context "signing up a new user" do
let(:manager_invitation) { instance_double(ManagerInvitationJob) }
let(:mail_mock) { double(:mailer, deliver_later: true) }
before do
setup_email
allow(EnterpriseMailer).to receive(:manager_invitation).
with(enterprise, kind_of(Spree::User)) { mail_mock }
allow(controller).to receive_messages spree_current_user: admin
end
it 'enqueues an invitation email' do
expect(ManagerInvitationJob)
.to receive(:perform_later).with(enterprise.id, kind_of(Integer))
expect(mail_mock).to receive(:deliver_later)
spree_post :create, email: 'un.registered@email.com', enterprise_id: enterprise.id
end

View File

@@ -1,15 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
describe ConfirmSignupJob do
let(:user) { create(:user) }
it "sends a confirmation email to the user" do
mail = double(:mail)
expect(Spree::UserMailer).to receive(:signup_confirmation).with(user).and_return(mail)
expect(mail).to receive(:deliver_now)
ConfirmSignupJob.perform_now(user.id)
end
end

View File

@@ -1,15 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
describe WelcomeEnterpriseJob do
let(:enterprise) { create(:enterprise) }
it "sends a welcome email to the enterprise" do
mail = double(:mail)
expect(EnterpriseMailer).to receive(:welcome).with(enterprise).and_return(mail)
expect(mail).to receive(:deliver_now)
WelcomeEnterpriseJob.perform_now(enterprise.id)
end
end

View File

@@ -11,7 +11,9 @@ describe Enterprise do
it "sends a welcome email" do
expect do
create(:enterprise, owner: user)
end.to enqueue_job WelcomeEnterpriseJob
end.to enqueue_job ActionMailer::DeliveryJob
expect(enqueued_jobs.last.to_s).to match "welcome"
end
end
end

View File

@@ -111,7 +111,9 @@ describe Spree::User do
expect do
create(:user, confirmed_at: nil).confirm
end.to enqueue_job ConfirmSignupJob
end.to enqueue_job ActionMailer::DeliveryJob
expect(enqueued_jobs.last.to_s).to match "signup_confirmation"
end
end