Skip to content

Instantly share code, notes, and snippets.

@rbazinet
Forked from scottwater/email_queue.rb
Created February 18, 2012 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbazinet/1857661 to your computer and use it in GitHub Desktop.
Save rbazinet/1857661 to your computer and use it in GitHub Desktop.
EmailQueue for Sidekiq
class EmailQueue
include Sidekiq::Worker
def perform(options)
mailer = options['mailer'].constantize
method = options['method']
args = options['args']
mailer.send(method, *args).deliver
end
def self.enqueue(mailer_klass, method, *args)
options = {'mailer' => mailer_klass.to_s, 'method' => method, 'args' => args}
self.perform_async(options)
end
end
RSpec::Matchers.define :have_queued_email do |expected|
match do |actual|
EmailQueue.jobs.any?{|job| job['args'] == [expected.merge('mailer' => actual.to_s)]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment