resque_mailer 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -1
- data/VERSION +1 -1
- data/lib/resque_mailer.rb +29 -10
- data/resque_mailer.gemspec +2 -2
- data/spec/resque_mailer_spec.rb +15 -3
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
### 2.0.
|
1
|
+
### 2.0.1 / 2011-08-19
|
2
|
+
|
3
|
+
* Restore the mailer proxy object so mailer method bodies never get
|
4
|
+
invoked more than once accidentally (not required to be idempotent)
|
5
|
+
|
6
|
+
### 2.0.0 / 2011-06-24
|
2
7
|
|
3
8
|
* Removed support for legacy Rails 2.x applications (please use v1.x)
|
4
9
|
* Removed mailer proxy, return Mail::Message object
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.1
|
data/lib/resque_mailer.rb
CHANGED
@@ -26,16 +26,7 @@ module Resque
|
|
26
26
|
return super if environment_excluded?
|
27
27
|
|
28
28
|
if action_methods.include?(method_name.to_s)
|
29
|
-
|
30
|
-
mailer_class = self
|
31
|
-
super.tap do |resque_mail|
|
32
|
-
resque_mail.class_eval do
|
33
|
-
define_method(:deliver) do
|
34
|
-
resque.enqueue(mailer_class, method_name, *args)
|
35
|
-
self
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
29
|
+
MessageDecoy.new(self, method_name, *args)
|
39
30
|
else
|
40
31
|
super
|
41
32
|
end
|
@@ -61,5 +52,33 @@ module Resque
|
|
61
52
|
::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
|
62
53
|
end
|
63
54
|
end
|
55
|
+
|
56
|
+
class MessageDecoy
|
57
|
+
def initialize(mailer_class, method_name, *args)
|
58
|
+
@mailer_class = mailer_class
|
59
|
+
@method_name = method_name
|
60
|
+
*@args = *args
|
61
|
+
end
|
62
|
+
|
63
|
+
def resque
|
64
|
+
::Resque::Mailer.default_queue_target
|
65
|
+
end
|
66
|
+
|
67
|
+
def actual_message
|
68
|
+
@actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
|
69
|
+
end
|
70
|
+
|
71
|
+
def deliver
|
72
|
+
resque.enqueue(@mailer_class, @method_name, *@args)
|
73
|
+
end
|
74
|
+
|
75
|
+
def deliver!
|
76
|
+
actual_message.deliver
|
77
|
+
end
|
78
|
+
|
79
|
+
def method_missing(method_name, *args)
|
80
|
+
actual_message.send(method_name, *args)
|
81
|
+
end
|
82
|
+
end
|
64
83
|
end
|
65
84
|
end
|
data/resque_mailer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{resque_mailer}
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nick Plante"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-19}
|
13
13
|
s.description = %q{Rails plugin for sending asynchronous email with ActionMailer and Resque}
|
14
14
|
s.email = %q{nap@zerosum.org}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/resque_mailer_spec.rb
CHANGED
@@ -10,6 +10,7 @@ class Rails3Mailer < ActionMailer::Base
|
|
10
10
|
MAIL_PARAMS = { :to => "crafty@example.org" }
|
11
11
|
|
12
12
|
def test_mail(*params)
|
13
|
+
Resque::Mailer.success!
|
13
14
|
mail(*params)
|
14
15
|
end
|
15
16
|
end
|
@@ -19,6 +20,7 @@ describe Resque::Mailer do
|
|
19
20
|
|
20
21
|
before do
|
21
22
|
Resque::Mailer.default_queue_target = resque
|
23
|
+
Resque::Mailer.stub(:success!)
|
22
24
|
Rails3Mailer.stub(:current_env => :test)
|
23
25
|
end
|
24
26
|
|
@@ -64,6 +66,11 @@ describe Resque::Mailer do
|
|
64
66
|
@delivery.call
|
65
67
|
end
|
66
68
|
end
|
69
|
+
|
70
|
+
it 'should not invoke the method body more than once' do
|
71
|
+
Resque::Mailer.should_not_receive(:success!)
|
72
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).deliver
|
73
|
+
end
|
67
74
|
end
|
68
75
|
|
69
76
|
describe '#deliver!' do
|
@@ -72,7 +79,7 @@ describe Resque::Mailer do
|
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
75
|
-
describe
|
82
|
+
describe 'perform' do
|
76
83
|
it 'should perform a queued mailer job' do
|
77
84
|
lambda {
|
78
85
|
Rails3Mailer.perform(:test_mail, Rails3Mailer::MAIL_PARAMS)
|
@@ -80,11 +87,16 @@ describe Resque::Mailer do
|
|
80
87
|
end
|
81
88
|
end
|
82
89
|
|
83
|
-
describe
|
84
|
-
it
|
90
|
+
describe 'original mail methods' do
|
91
|
+
it 'should be preserved' do
|
85
92
|
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).subject.should == 'Subject'
|
86
93
|
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).from.should include('from@example.org')
|
87
94
|
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).to.should include('crafty@example.org')
|
88
95
|
end
|
96
|
+
|
97
|
+
it 'should require execution of the method body prior to queueing' do
|
98
|
+
Resque::Mailer.should_receive(:success!).once
|
99
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).subject
|
100
|
+
end
|
89
101
|
end
|
90
102
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 1
|
10
|
+
version: 2.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nick Plante
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-19 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|