Skip to content
Browse files

first actual working version

  • Loading branch information...
1 parent 8ab86f5 commit dede2b1c1a5531e687520dda652b650463673035 @scottwater committed Sep 5, 2011
Showing with 59 additions and 19 deletions.
  1. +2 −2 Gemfile.lock
  2. +10 −8 lib/resque_mail_queue.rb
  3. +6 −9 resque_mail_queue.gemspec
  4. +41 −0 spec/resque_mail_queue_spec.rb
View
4 Gemfile.lock
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
- resque_mail_queue (0.0.1)
- actionmailer (~> 3.0.0)
+ resque_mail_queue (0.0.10)
+ actionmailer (>= 3.0.0)
resque (>= 1.1.0)
GEM
View
18 lib/resque_mail_queue.rb
@@ -1,17 +1,19 @@
+require 'resque'
+
module Resque
module MailQueue
+
+ include Resque::Helpers
extend self
def queue
:default
end
def perform(options = {})
- options = options.with_indifferent_access
-
- mailer = options[:klass].constantize
- method = options[:method]
- mailer.send(method, *options[:args]).deliver
+ mailer = constantize(options['klass'])
+ method = options['method']
+ mailer.send(method, *options['args']).deliver
end
def enqueue()
@@ -26,15 +28,15 @@ def initialize(klass)
def method_missing(m, *args, &block)
if @klass.respond_to? m
- options = {:klass => @klass.to_s, :method => m, :args => args}
- Resque.enqueue(MailQueue, options)
+ options = {'klass' => @klass.to_s, 'method' => m, 'args' => args}
+ Resque.enqueue(@klass, options)
else
super
end
end
end
- VERSION = '0.0.1'
+ VERSION = '0.0.10'
end
end
View
15 resque_mail_queue.gemspec
@@ -1,15 +1,15 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "lib/resque_mail_queue"
+require "resque_mail_queue"
Gem::Specification.new do |s|
s.name = "resque_mail_queue"
s.version = Resque::MailQueue::VERSION
s.authors = ["Scott Watermasysk"]
s.email = ["scottwater@gmail.com"]
- s.homepage = ""
- s.summary = %q{TODO: Write a gem summary}
- s.description = %q{TODO: Write a gem description}
+ s.homepage = "http://www.scottw.com"
+ s.summary = %q{Quickly enqueue action_mailer mails in resque}
+ s.description = %q{See summary}
s.rubyforge_project = "resque_mail_queue"
@@ -18,12 +18,9 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency 'actionmailer', '~> 3.0.0'
+ s.add_dependency 'actionmailer', '>= 3.0.0'
+
s.add_dependency 'resque', '>= 1.1.0'
s.add_development_dependency 'resque_spec', '>= 0.7.0'
-
- # specify any dependencies here; for example:
- # s.add_development_dependency "rspec"
- # s.add_runtime_dependency "rest-client"
end
View
41 spec/resque_mail_queue_spec.rb
@@ -0,0 +1,41 @@
+$:.push File.expand_path('../lib', __FILE__)
+require 'resque_mail_queue'
+require 'resque_spec'
+
+class DumbMailer
+ extend Resque::MailQueue
+ def self.send_mail(user_id)
+ end
+end
+
+class DumbMailer2 < DumbMailer
+ def self.queue
+ :not_default
+ end
+end
+
+
+describe Resque::MailQueue do
+
+ before(:each) do
+ ResqueSpec.reset!
+ end
+
+ it 'should find a dummy mail in the default queue' do
+ DumbMailer.enqueue.send_mail(3)
+ DumbMailer.should have_queued('klass' => 'DumbMailer', 'method' => :send_mail, 'args' => [3]).in(:default)
+ end
+
+ it 'should be able to override the queue (not default)' do
+ DumbMailer2.enqueue.send_mail(3)
+ DumbMailer2.should have_queued('klass' => 'DumbMailer2', 'method'=> :send_mail, 'args' => [3]).in(:not_default)
+
+ end
+
+ it 'should call deliver when pulling an item from the queue' do
+ mail_message = double('mail_message')
+ DumbMailer.stub(:send_mail).and_return(mail_message)
+ mail_message.should_receive(:deliver)
+ Resque::MailQueue.perform('klass' => 'DumbMailer', 'method' => :send_mail, 'args' => [3])
+ end
+end

0 comments on commit dede2b1

Please sign in to comment.
Something went wrong with that request. Please try again.