resque_mailer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,42 +1,48 @@
1
1
  = ResqueMailer
2
2
 
3
3
  A gem plugin which allows messages prepared by ActionMailer to be delivered asynchronously.
4
- Assumes that you are using Resque (http://github.com/defunkt/resque) for your background jobs.
4
+ Assumes that you're using Resque (http://github.com/defunkt/resque) for your background jobs.
5
5
 
6
6
  == Usage
7
7
 
8
8
  Include Resque::Mailer in your ActionMailer subclass(es) like this:
9
9
 
10
- class MyMailer < ActionMailer::Base
11
- include Resque::Mailer
12
- end
10
+ class MyMailer < ActionMailer::Base
11
+ include Resque::Mailer
12
+ end
13
+
14
+ Or if you want to always use asynchronous delivery by default, create an initializer in your
15
+ Rails project or piggyback on your load_resque.rb initializer:
16
+
17
+ class ActionMailer::Base
18
+ include Resque::Mailer
19
+ end
13
20
 
14
21
  Now, when MyMailer.deliver_subject_email is called, an entry will be created in the job queue.
15
- Note that you can still have mail delivered synchronously by using the bang method variant:
16
- MyMailer.deliver_subject_email!
22
+ Your Resque workers will be able to deliver this for you; the queue we're using is imaginatively
23
+ named +mailer+. Just make sure your workers know about it and are loading your environment:
17
24
 
18
- To always use asynchronous delivery by default, create an initializer in your Rails project like so:
25
+ QUEUE=mailer rake environment resque:work
19
26
 
20
- # config/initializers/resque_mailer.rb
21
- class ActionMailer::Base
22
- include Resque::Mailer
23
- end
27
+ Note that you can still have mail delivered synchronously by using the bang method variant:
28
+ MyMailer.deliver_subject_email!
24
29
 
25
30
  == Installation
26
31
 
27
32
  Install it as a plugin or as a gem plugin.
28
33
 
29
- script/plugin install git://github.com/zapnap/resque_mailer.git
34
+ script/plugin install git://github.com/zapnap/resque_mailer.git
30
35
 
31
- config.gem 'resque_mailer'
36
+ # config/environment.rb
37
+ config.gem 'resque_mailer'
32
38
 
33
39
  == Testing
34
40
 
35
41
  You don't want to be sending actual emails in the test environment, so you can configure the
36
- environments that should be excluded.
42
+ environments that should be excluded like so:
37
43
 
38
- # config/initializers/resque_mailer.rb
39
- Resque::Mailer.excluded_environments = [:test, :cucumber]
44
+ # config/initializers/resque_mailer.rb
45
+ Resque::Mailer.excluded_environments = [:test, :cucumber]
40
46
 
41
47
  == Note on Patches / Pull Requests
42
48
 
@@ -49,5 +55,5 @@ Resque::Mailer.excluded_environments = [:test, :cucumber]
49
55
 
50
56
  == Credits
51
57
 
52
- This work is basically a forked version of delayed_job_mailer http://github.com/andersondias/delayed_job_mailer) by Anderson Dias
58
+ This work is essentially a forked version of delayed_job_mailer (http://github.com/andersondias/delayed_job_mailer) by Anderson Dias
53
59
  (which in turn was inspired by Alexander Lang's workling_mailer). Enhanced and modified to work with Resque by Nick Plante.
data/Rakefile CHANGED
@@ -11,6 +11,8 @@ begin
11
11
  gem.homepage = "http://github.com/zapnap/resque_mailer"
12
12
  gem.authors = ["Nick Plante"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "resque", ">= 1.2.3"
15
+ gem.add_development_dependency "actionmailer", ">= 2.2.2"
14
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
17
  end
16
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/resque_mailer.rb CHANGED
@@ -15,10 +15,18 @@ module Resque
15
15
 
16
16
  case method_symbol.id2name
17
17
  when /^deliver_([_a-z]\w*)\!/ then super(method_symbol, *params)
18
- when /^deliver_([_a-z]\w*)/ then Resque.enqueue("#{method_symbol}!", *params)
18
+ when /^deliver_([_a-z]\w*)/ then ::Resque.enqueue(self, "#{method_symbol}!", *params)
19
19
  else super(method_symbol, *params)
20
20
  end
21
21
  end
22
+
23
+ def queue
24
+ :mailer
25
+ end
26
+
27
+ def perform(cmd, *args)
28
+ send(cmd, *args)
29
+ end
22
30
  end
23
31
 
24
32
  def self.excluded_environments=(*environments)
@@ -32,17 +32,17 @@ describe AsynchTestMailer do
32
32
  Resque.stub(:enqueue)
33
33
  end
34
34
 
35
- it 'should not deliver the email at this moment' do
35
+ it 'should not deliver the email synchronously' do
36
36
  AsynchTestMailer.deliver_test_mail *@params
37
37
  @emails.size.should == 0
38
38
  end
39
39
 
40
- it 'should send deliver action to delayed job list' do
41
- Resque.should_receive(:enqueue).with('deliver_test_mail!', *@params)
40
+ it 'should place the deliver action one the Resque mailer queue' do
41
+ Resque.should_receive(:enqueue).with(AsynchTestMailer, 'deliver_test_mail!', *@params)
42
42
  AsynchTestMailer.deliver_test_mail *@params
43
43
  end
44
44
 
45
- it 'should not send deliver action to delayed job list for environments where delayed job mailer is disabled' do
45
+ it 'should not send deliver action to queue for environments where asychronous delivery is disabled' do
46
46
  excluded_environments = [:cucumber, :foo, 'bar']
47
47
  ::Resque::Mailer.excluded_environments = excluded_environments
48
48
 
@@ -64,4 +64,13 @@ describe AsynchTestMailer do
64
64
  emails.size.should == 1
65
65
  end
66
66
  end
67
+
68
+ it 'should have a queue' do
69
+ AsynchTestMailer.queue.should == :mailer
70
+ end
71
+
72
+ it 'should perform a queued mailer job' do
73
+ AsynchTestMailer.should_receive("deliver_test_mail!").with(1, { :foo => 'bar' })
74
+ AsynchTestMailer.perform("deliver_test_mail!", 1, { :foo => 'bar' })
75
+ end
67
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Plante
@@ -22,6 +22,26 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.2.9
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: resque
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: actionmailer
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.2.2
44
+ version:
25
45
  description: Rails plugin for sendings asynchronous email with ActionMailer and Resque
26
46
  email: nap@zerosum.org
27
47
  executables: []