Skip to content

Instantly share code, notes, and snippets.

@scottwater
Created February 17, 2012 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save scottwater/1854576 to your computer and use it in GitHub Desktop.
Save scottwater/1854576 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