mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Add jobs for user, order and enterprise emails
This commit is contained in:
6
app/jobs/confirm_order_job.rb
Normal file
6
app/jobs/confirm_order_job.rb
Normal 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
|
||||
6
app/jobs/confirm_signup_job.rb
Normal file
6
app/jobs/confirm_signup_job.rb
Normal 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
|
||||
6
app/jobs/welcome_enterprise_job.rb
Normal file
6
app/jobs/welcome_enterprise_job.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
WelcomeEnterpriseJob = Struct.new(:enterprise_id) do
|
||||
def perform
|
||||
enterprise = Enterprise.find enterprise_id
|
||||
EnterpriseMailer.welcome(enterprise).deliver
|
||||
end
|
||||
end
|
||||
16
spec/jobs/confirm_order_job_spec.rb
Normal file
16
spec/jobs/confirm_order_job_spec.rb
Normal 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
|
||||
13
spec/jobs/confirm_signup_job_spec.rb
Normal file
13
spec/jobs/confirm_signup_job_spec.rb
Normal 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
|
||||
13
spec/jobs/welcome_enterprise_job_spec.rb
Normal file
13
spec/jobs/welcome_enterprise_job_spec.rb
Normal 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
|
||||
@@ -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 = {})
|
||||
|
||||
Reference in New Issue
Block a user