Test email through resque queue #11692
parent
f858216be4
commit
ca818a9dc2
@ -0,0 +1,12 @@
|
|||||||
|
module CartoGearsApi
|
||||||
|
module Mailer
|
||||||
|
class TestMail < ActionMailer::Base
|
||||||
|
def test_mail(from, to, subject)
|
||||||
|
@from = from
|
||||||
|
@to = to
|
||||||
|
@subject = subject
|
||||||
|
mail(to: to, from: from, subject: subject).deliver
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
<h1><%= @subject %></h1>
|
||||||
|
<h2>from: <%= @from %></h2>
|
||||||
|
<h2>to: <%= @to %></h2>
|
||||||
|
|
||||||
|
This is a test email
|
@ -0,0 +1,13 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
module CartoGearsApi
|
||||||
|
module Queue
|
||||||
|
class GenericJob
|
||||||
|
@queue = :gears
|
||||||
|
|
||||||
|
def self.perform(class_name, method, *args)
|
||||||
|
Object.const_get(class_name).send(method, *args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
module CartoGearsApi
|
||||||
|
module Queue
|
||||||
|
class JobsService
|
||||||
|
def send_job(class_name, method, *args)
|
||||||
|
::Resque.enqueue(CartoGearsApi::Queue::GenericJob, class_name, method, *args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,16 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require 'carto_gears_api/queue/generic_job'
|
||||||
|
require 'carto_gears_api/test_mail'
|
||||||
|
|
||||||
|
describe CartoGearsApi::Queue::GenericJob do
|
||||||
|
describe '#perform' do
|
||||||
|
it 'instantiates the class, and invokes the method with random parameters' do
|
||||||
|
CartoGearsApi::TestMail.any_instance.should_receive(:test_mail).with('param1', 2)
|
||||||
|
CartoGearsApi::Queue::GenericJob.new.perform(CartoGearsApi::Mailer::TestMail,
|
||||||
|
:test_mail,
|
||||||
|
'support@carto.com',
|
||||||
|
'support@carto.com',
|
||||||
|
'Test email')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,21 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require 'carto_gears_api/queue/jobs_service'
|
||||||
|
require 'carto_gears_api/queue/generic_job'
|
||||||
|
require 'carto_gears_api/test_mail'
|
||||||
|
|
||||||
|
describe CartoGearsApi::Queue::JobsService do
|
||||||
|
let(:service) { CartoGearsApi::Queue::JobsService.new }
|
||||||
|
|
||||||
|
module Resque; end
|
||||||
|
|
||||||
|
describe '#send_job' do
|
||||||
|
it 'enqueues a Resque::CartoGearsJobs::GenericJob#perform with the class, method and random parameters' do
|
||||||
|
::Resque.should_receive(:enqueue).with(CartoGearsApi::Queue::GenericJob,
|
||||||
|
CartoGearsApi::TestMail,
|
||||||
|
:test_mail,
|
||||||
|
'param1',
|
||||||
|
2)
|
||||||
|
service.send_job('CartoGearsApi::Mailer::TestMail', :test_mail, 'param1', 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,2 +1,2 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
VVERBOSE=true QUEUE=imports,exports,users,user_dbs,geocodings,synchronizations,tracker,user_migrations rake environment resque:work
|
VVERBOSE=true QUEUE=imports,exports,users,user_dbs,geocodings,synchronizations,tracker,user_migrations,gears rake environment resque:work
|
||||||
|
Loading…
Reference in new issue