Add jobs for user, order and enterprise emails

This commit is contained in:
Rohan Mitchell
2015-04-10 15:51:42 +10:00
parent af4baabb50
commit bb3bdf37cd
7 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
ConfirmOrderJob = Struct.new(:order_id) do
def perform
Spree::OrderMailer.confirm_email_for_customer(order_id).deliver
Spree::OrderMailer.confirm_email_for_shop(order_id).deliver
end
end

View File

@@ -0,0 +1,6 @@
ConfirmSignupJob = Struct.new(:user_id) do
def perform
user = Spree::User.find user_id
Spree::UserMailer.signup_confirmation(user).deliver
end
end

View File

@@ -0,0 +1,6 @@
WelcomeEnterpriseJob = Struct.new(:enterprise_id) do
def perform
enterprise = Enterprise.find enterprise_id
EnterpriseMailer.welcome(enterprise).deliver
end
end

View File

@@ -0,0 +1,16 @@
require 'spec_helper'
describe ConfirmOrderJob do
let(:order) { create(:order) }
it "sends confirmation emails to both the user and the shop owner" do
customer_confirm_fake = double(:confirm_email_for_customer)
shop_confirm_fake = double(:confirm_email_for_shop)
expect(Spree::OrderMailer).to receive(:confirm_email_for_customer).and_return customer_confirm_fake
expect(Spree::OrderMailer).to receive(:confirm_email_for_shop).and_return shop_confirm_fake
expect(customer_confirm_fake).to receive :deliver
expect(shop_confirm_fake).to receive :deliver
run_job ConfirmOrderJob.new order.id
end
end

View File

@@ -0,0 +1,13 @@
require 'spec_helper'
describe ConfirmSignupJob do
let(:user) { create(:user) }
it "sends a confirmation email to the user" do
mail = double(:mail)
Spree::UserMailer.should_receive(:signup_confirmation).with(user).and_return(mail)
mail.should_receive(:deliver)
run_job ConfirmSignupJob.new user.id
end
end

View File

@@ -0,0 +1,13 @@
require 'spec_helper'
describe WelcomeEnterpriseJob do
let(:enterprise) { create(:enterprise) }
it "sends a welcome email to the enterprise" do
mail = double(:mail)
EnterpriseMailer.should_receive(:welcome).with(enterprise).and_return(mail)
mail.should_receive(:deliver)
run_job WelcomeEnterpriseJob.new(enterprise.id)
end
end

View File

@@ -1,5 +1,12 @@
module OpenFoodNetwork
module DelayedJobHelper
def run_job(job)
clear_jobs
Delayed::Job.enqueue job
flush_jobs
end
# Process all pending Delayed jobs, keeping in mind jobs could spawn new
# delayed job (so things might be added to the queue while processing)
def flush_jobs(options = {})