resque-async_deliver 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/async_deliver/proxy.rb +13 -9
- data/lib/async_deliver/version.rb +1 -1
- data/spec/async_deliver/mail_job_spec.rb +3 -19
- data/spec/async_deliver/proxy_spec.rb +26 -25
- data/spec/support.rb +24 -0
- metadata +2 -2
data/lib/async_deliver/proxy.rb
CHANGED
@@ -3,19 +3,23 @@
|
|
3
3
|
module Resque::Plugins::AsyncDeliver
|
4
4
|
class Proxy
|
5
5
|
def initialize(klass)
|
6
|
-
@klass = klass
|
6
|
+
@klass = klass
|
7
7
|
end
|
8
8
|
|
9
|
-
def method_missing(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def method_missing(method_name, *args)
|
10
|
+
if Resque.inline?
|
11
|
+
@klass.__send__(method_name, *args).deliver
|
12
|
+
else
|
13
|
+
arguments = [ @klass.name, method_name ]
|
14
|
+
args.each do |a|
|
15
|
+
if a.class < ::ActiveRecord::Base
|
16
|
+
arguments << { :async_deliver_class => a.class.to_s, :async_deliver_id => a.id }
|
17
|
+
else
|
18
|
+
arguments << a
|
19
|
+
end
|
16
20
|
end
|
21
|
+
Resque.enqueue(MailJob, *arguments)
|
17
22
|
end
|
18
|
-
Resque.enqueue(MailJob, *arguments)
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -4,35 +4,19 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Resque::Plugins::AsyncDeliver::MailJob do
|
6
6
|
describe '.perform' do
|
7
|
-
let(:user) { TestUser.instance }
|
8
|
-
let(:resource) { TestResource.instance }
|
9
|
-
|
10
7
|
before do
|
11
8
|
message = mock()
|
12
9
|
message.expects(:deliver)
|
13
10
|
|
14
|
-
TestMailer.expects(:test_message).with(
|
15
|
-
user,
|
16
|
-
123,
|
17
|
-
"a string",
|
18
|
-
%q[ an array ],
|
19
|
-
{ :a => 'hash' },
|
20
|
-
resource
|
21
|
-
).returns(message)
|
11
|
+
TestMailer.expects(:test_message).with(*arguments).returns(message)
|
22
12
|
end
|
23
13
|
|
24
14
|
it 'should instantiate a mail and deliver it' do
|
25
15
|
Resque::Plugins::AsyncDeliver::MailJob.perform(
|
26
16
|
'TestMailer',
|
27
17
|
:test_message,
|
28
|
-
|
29
|
-
|
30
|
-
123,
|
31
|
-
"a string",
|
32
|
-
%q[ an array ],
|
33
|
-
{ :a => 'hash' },
|
34
|
-
{ :async_deliver_class => 'TestResource',
|
35
|
-
:async_deliver_id => resource.id })
|
18
|
+
*serialized_arguments
|
19
|
+
)
|
36
20
|
end
|
37
21
|
end
|
38
22
|
end
|
@@ -5,34 +5,35 @@ require 'spec_helper'
|
|
5
5
|
describe Resque::Plugins::AsyncDeliver::Proxy do
|
6
6
|
describe '#method_missing' do
|
7
7
|
let(:proxy) { Resque::Plugins::AsyncDeliver::Proxy.new(TestMailer) }
|
8
|
-
let(:user) { TestUser.instance }
|
9
|
-
let(:resource) { TestResource.instance }
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
Resque
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
9
|
+
context 'when Resque.inline? == false' do
|
10
|
+
before do
|
11
|
+
Resque.expects(:enqueue).with(
|
12
|
+
Resque::Plugins::AsyncDeliver::MailJob,
|
13
|
+
'TestMailer',
|
14
|
+
:test_message,
|
15
|
+
*serialized_arguments
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should enqueue a MailJob in Resque' do
|
20
|
+
proxy.test_message(*arguments)
|
21
|
+
end
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
context 'when Resque.inline? == true' do
|
25
|
+
before do
|
26
|
+
Resque.inline = true
|
27
|
+
Resque.expects(:enqueue).never
|
28
|
+
|
29
|
+
message = mock()
|
30
|
+
message.expects(:deliver)
|
31
|
+
TestMailer.expects(:test_message).with(*arguments).returns(message)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should deliver the mail instantly' do
|
35
|
+
proxy.test_message(*arguments)
|
36
|
+
end
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
data/spec/support.rb
CHANGED
@@ -22,3 +22,27 @@ class TestMailer < ActionMailer::Base
|
|
22
22
|
extend Resque::Plugins::AsyncDeliver::ActionMailerExtension
|
23
23
|
def test_message; end
|
24
24
|
end
|
25
|
+
|
26
|
+
def arguments
|
27
|
+
[
|
28
|
+
TestUser.instance,
|
29
|
+
123,
|
30
|
+
"a string",
|
31
|
+
%q[ an array ],
|
32
|
+
{ :a => 'hash' },
|
33
|
+
TestResource.instance
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
def serialized_arguments
|
38
|
+
[
|
39
|
+
{ :async_deliver_class => 'TestUser',
|
40
|
+
:async_deliver_id => TestUser.instance.id },
|
41
|
+
123,
|
42
|
+
"a string",
|
43
|
+
%q[ an array ],
|
44
|
+
{ :a => 'hash' },
|
45
|
+
{ :async_deliver_class => 'TestResource',
|
46
|
+
:async_deliver_id => TestResource.instance.id }
|
47
|
+
]
|
48
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: resque-async_deliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Philipe Fatio
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-08 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|