VRFS-1483 added async support
This commit is contained in:
parent
40a2049bdf
commit
cdb271bf98
|
|
@ -40,6 +40,7 @@ gem 'resque'
|
|||
gem 'resque-retry'
|
||||
gem 'resque-failed-job-mailer' #, :path => "/Users/seth/workspace/resque_failed_job_mailer"
|
||||
gem 'resque-lonely_job', '~> 1.0.0'
|
||||
gem 'resque_mailer'
|
||||
gem 'oj'
|
||||
gem 'builder'
|
||||
gem 'fog'
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ require "jam_ruby/models/country"
|
|||
require "jam_ruby/models/region"
|
||||
require "jam_ruby/models/city"
|
||||
require "jam_ruby/models/email_batch"
|
||||
require "jam_ruby/app/mailers/async_mailer"
|
||||
require "jam_ruby/app/mailers/batch_mailer"
|
||||
|
||||
include Jampb
|
||||
|
|
|
|||
|
|
@ -1,17 +1,31 @@
|
|||
module JamRuby
|
||||
class BatchMailer < ActionMailer::Base
|
||||
include SendGrid
|
||||
|
||||
class BatchMailer < JamRuby::AsyncMailer
|
||||
layout "batch_mailer"
|
||||
|
||||
sendgrid_category :batch_email
|
||||
sendgrid_category :use_subject_lines
|
||||
sendgrid_unique_args :env => Environment.mode
|
||||
|
||||
def send_batch_email(batch, user)
|
||||
@user = user
|
||||
def send_batch_email(batch_id, user_id)
|
||||
@user = User.where(:id => user_id).limit(1).first
|
||||
batch = EmailBatch.where(:id => batch_id).limit(1).first
|
||||
@body = batch.merged_body(user)
|
||||
mail(:to => user.email, :from => batch.from_email, :subject => batch.subject) do |format|
|
||||
|
||||
mail(:to => user.email,
|
||||
:from => batch.from_email,
|
||||
:subject => batch.subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def send_batch_email_test(batch_id, email_addy)
|
||||
batch = EmailBatch.where(:id => batch_id).limit(1).first
|
||||
@body = batch.body
|
||||
|
||||
mail(:to => email_addy,
|
||||
:from => batch.from_email,
|
||||
:subject => batch.subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ module JamRuby
|
|||
|
||||
def send_test_batch
|
||||
self.test_users.each do |uu|
|
||||
BatchMailer.send_batch_email(self, uu).deliver
|
||||
BatchMailer.send_batch_email_test(self.id, uu.email).deliver
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ describe BatchMailer do
|
|||
|
||||
batch = FactoryGirl.create(:email_batch)
|
||||
batch.send_test_batch
|
||||
|
||||
it { BatchMailer.deliveries.length.should == 4 }
|
||||
|
||||
it { mail['from'].to_s.should == EmailBatch::DEFAULT_SENDER }
|
||||
|
|
@ -14,7 +15,7 @@ describe BatchMailer do
|
|||
it { mail.subject.should == batch.subject }
|
||||
|
||||
it { mail.multipart?.should == true } # because we send plain + html
|
||||
it { mail.parts[1].decode_body.should match(/#{Regexp.escape(batch.merged_body(batch.test_users[0]))}/) }
|
||||
it { mail.text_part.decode_body.should match(/#{Regexp.escape(batch.body)}/) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue