resque-async_deliver 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +5 -0
- data/README.md +6 -0
- data/lib/resque/async_deliver.rb +1 -0
- data/lib/resque/plugins/async_deliver/action_mailer_extension.rb +17 -0
- data/lib/resque/plugins/async_deliver/mail_job.rb +14 -0
- data/lib/resque/plugins/async_deliver/proxy.rb +21 -0
- data/lib/resque/plugins/async_deliver/railtie.rb +13 -0
- data/lib/resque/plugins/async_deliver/serializer.rb +64 -0
- data/lib/{async_deliver → resque/plugins/async_deliver}/version.rb +1 -1
- data/lib/resque/plugins/async_deliver.rb +12 -0
- data/resque-async_deliver.gemspec +3 -5
- data/spec/spec_helper.rb +2 -3
- data/spec/support.rb +6 -32
- data/spec/unit/action_mailer_spec.rb +12 -0
- data/spec/unit/async_deliver_spec.rb +9 -0
- data/spec/unit/mail_job_spec.rb +20 -0
- data/spec/unit/proxy_spec.rb +38 -0
- data/spec/unit/serializer_spec.rb +60 -0
- metadata +36 -56
- data/lib/async_deliver/action_mailer_extension.rb +0 -15
- data/lib/async_deliver/mail_job.rb +0 -23
- data/lib/async_deliver/proxy.rb +0 -25
- data/lib/async_deliver/railtie.rb +0 -13
- data/lib/resque-async_deliver.rb +0 -17
- data/spec/async_deliver/action_mailer_extension_spec.rb +0 -15
- data/spec/async_deliver/async_deliver_spec.rb +0 -13
- data/spec/async_deliver/mail_job_spec.rb +0 -22
- data/spec/async_deliver/proxy_spec.rb +0 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b283af21a0c77dcef7845b93bbe22bfc18f44a45
|
4
|
+
data.tar.gz: 4189c75db01030a83d39eaa98e1b0815e7e9cf27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f91650e1b1fd0f3964983dc8cda42f389afe390602e54e397fd5b972c910da83c13e523c2562d3d1bde69f58fbfc2f8495d7eb36c40c144b27bf7d672d987ac1
|
7
|
+
data.tar.gz: ae53e96972a0a40090a8a3730c753bdf5c2c163be6c26dc716dd90382e6f7328a446f81dc3396a6bbeacc8ec08676fca82e00f6b8e2db4532aaacd2718cfa63c
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,8 @@ serialized as a hash containing the class and the id of the model.
|
|
39
39
|
resque-async\_deliver will then `find` the records and pass them to the
|
40
40
|
mailer.
|
41
41
|
|
42
|
+
The jobs will be added to Resque in the `mail` queue.
|
43
|
+
|
42
44
|
## Details
|
43
45
|
|
44
46
|
Tested on ruby 1.8.7 and 1.9.2.
|
@@ -55,3 +57,7 @@ Tested on ruby 1.8.7 and 1.9.2.
|
|
55
57
|
Philipe Fatio
|
56
58
|
<philipe.fatio@gmail.com>
|
57
59
|
[@fphilipe](http://twitter.com/fphilipe)
|
60
|
+
|
61
|
+
|
62
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/fphilipe/resque-async_deliver/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
63
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'resque/plugins/async_deliver'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
|
3
|
+
module Resque
|
4
|
+
module Plugins
|
5
|
+
module AsyncDeliver
|
6
|
+
module ActionMailerExtension
|
7
|
+
def async_deliver
|
8
|
+
Proxy.new(self)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.initialize
|
13
|
+
ActionMailer::Base.send(:extend, ActionMailerExtension)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Resque
|
2
|
+
module Plugins
|
3
|
+
module AsyncDeliver
|
4
|
+
class Proxy
|
5
|
+
attr_reader :klass
|
6
|
+
|
7
|
+
def initialize(klass)
|
8
|
+
@klass = klass
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(*args)
|
12
|
+
if Resque.inline?
|
13
|
+
klass.send(*args).deliver
|
14
|
+
else
|
15
|
+
Resque.enqueue(MailJob, *Serializer.serialize(klass, *args))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Resque
|
2
|
+
module Plugins
|
3
|
+
module AsyncDeliver
|
4
|
+
module Serializer
|
5
|
+
CLASS_KEY = 'async_deliver_class'
|
6
|
+
ID_KEY = 'async_deliver_id'
|
7
|
+
|
8
|
+
def self.serialize(*args)
|
9
|
+
mailer = args.shift.to_s
|
10
|
+
method_name = args.shift.to_s
|
11
|
+
arguments = serialize_collection(args)
|
12
|
+
|
13
|
+
[mailer, method_name, *arguments]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.deserialize(*args)
|
17
|
+
mailer = args.shift.constantize
|
18
|
+
method_name = args.shift.to_sym
|
19
|
+
arguments = deserialize_collection(args)
|
20
|
+
|
21
|
+
[mailer, method_name, *arguments]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.serialize_obj(arg)
|
27
|
+
if arg.class.respond_to?(:find) and arg.respond_to?(:id)
|
28
|
+
{ CLASS_KEY => arg.class.to_s, ID_KEY => arg.id }
|
29
|
+
else
|
30
|
+
serialize_collection(arg)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.deserialize_obj(arg)
|
35
|
+
if arg.is_a?(Hash) and arg.key?(CLASS_KEY) and arg.key?(ID_KEY)
|
36
|
+
arg[CLASS_KEY].constantize.find(arg[ID_KEY])
|
37
|
+
else
|
38
|
+
deserialize_collection(arg)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.serialize_collection(obj)
|
43
|
+
if obj.is_a?(Array)
|
44
|
+
obj.map { |i| serialize_obj(i) }
|
45
|
+
elsif obj.is_a?(Hash)
|
46
|
+
Hash[obj.map { |k,v| [serialize_obj(k), serialize_obj(v)] }]
|
47
|
+
else
|
48
|
+
obj
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.deserialize_collection(obj)
|
53
|
+
if obj.is_a?(Array)
|
54
|
+
obj.map { |i| deserialize_obj(i) }
|
55
|
+
elsif obj.is_a?(Hash)
|
56
|
+
Hash[obj.map { |k,v| [deserialize_obj(k), deserialize_obj(v)] }]
|
57
|
+
else
|
58
|
+
obj
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'resque'
|
2
|
+
|
3
|
+
require 'resque/plugins/async_deliver/mail_job'
|
4
|
+
require 'resque/plugins/async_deliver/serializer'
|
5
|
+
require 'resque/plugins/async_deliver/proxy'
|
6
|
+
require 'resque/plugins/async_deliver/action_mailer_extension'
|
7
|
+
|
8
|
+
if defined? Rails
|
9
|
+
require 'resque/plugins/async_deliver/railtie'
|
10
|
+
else
|
11
|
+
Resque::Plugins::AsyncDeliver.initialize
|
12
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: UTF-8
|
2
2
|
|
3
3
|
$:.push File.expand_path("../lib", __FILE__)
|
4
|
-
require "async_deliver/version"
|
4
|
+
require "resque/plugins/async_deliver/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "resque-async_deliver"
|
@@ -26,9 +26,7 @@ transformed back to records by the mailer job and passed along to the mailer.
|
|
26
26
|
s.require_paths = ["lib"]
|
27
27
|
|
28
28
|
s.add_dependency 'resque' , '~> 1.0'
|
29
|
-
s.add_dependency 'actionmailer', '
|
29
|
+
s.add_dependency 'actionmailer', '>= 3', '< 5'
|
30
30
|
|
31
|
-
s.add_development_dependency 'rspec
|
32
|
-
s.add_development_dependency 'rspec-expectations'
|
33
|
-
s.add_development_dependency 'mocha'
|
31
|
+
s.add_development_dependency 'rspec', '>= 3.0.0.beta1'
|
34
32
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
require 'resque'
|
2
|
-
require 'resque
|
2
|
+
require 'resque/async_deliver'
|
3
3
|
require 'action_mailer'
|
4
4
|
require 'singleton'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.find(id); instance; end
|
10
|
-
end
|
6
|
+
class Model
|
7
|
+
include Singleton
|
8
|
+
def self.find(id); instance; end
|
11
9
|
end
|
12
10
|
|
13
|
-
class TestUser <
|
11
|
+
class TestUser < Model
|
14
12
|
def id; 123; end
|
15
13
|
end
|
16
14
|
|
17
|
-
class TestResource <
|
15
|
+
class TestResource < Model
|
18
16
|
def id; 456; end
|
19
17
|
end
|
20
18
|
|
@@ -22,27 +20,3 @@ class TestMailer < ActionMailer::Base
|
|
22
20
|
extend Resque::Plugins::AsyncDeliver::ActionMailerExtension
|
23
21
|
def test_message; end
|
24
22
|
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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActionMailer::Base do
|
4
|
+
describe '.async_deliver' do
|
5
|
+
it 'returns a proxy for the mailer' do
|
6
|
+
proxy = TestMailer.async_deliver
|
7
|
+
|
8
|
+
expect(proxy).to be_a(Resque::Plugins::AsyncDeliver::Proxy)
|
9
|
+
expect(proxy.klass).to be(TestMailer)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resque::Plugins::AsyncDeliver::MailJob do
|
4
|
+
describe '.perform' do
|
5
|
+
it 'instantiates a mail and delivers it' do
|
6
|
+
message = double(deliver: true)
|
7
|
+
allow(TestMailer).to receive(:test_message) { message }
|
8
|
+
|
9
|
+
described_class.perform(
|
10
|
+
'TestMailer',
|
11
|
+
:test_message,
|
12
|
+
'hello',
|
13
|
+
'world'
|
14
|
+
)
|
15
|
+
|
16
|
+
expect(TestMailer).to have_received(:test_message).with('hello', 'world')
|
17
|
+
expect(message).to have_received(:deliver)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resque::Plugins::AsyncDeliver::Proxy do
|
4
|
+
let(:proxy) { described_class.new(TestMailer) }
|
5
|
+
|
6
|
+
context 'when calling a method on it' do
|
7
|
+
it 'enqueues a MailJob' do
|
8
|
+
allow(Resque).to receive(:enqueue)
|
9
|
+
|
10
|
+
proxy.test_message('hello', 'world')
|
11
|
+
|
12
|
+
expect(Resque).to have_received(:enqueue).with(
|
13
|
+
Resque::Plugins::AsyncDeliver::MailJob,
|
14
|
+
'TestMailer',
|
15
|
+
'test_message',
|
16
|
+
'hello',
|
17
|
+
'world'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when Resque.inline? is true' do
|
22
|
+
it 'delivers the mail without queuing' do
|
23
|
+
message = double(deliver: true)
|
24
|
+
allow(TestMailer).to receive(:test_message) { message }
|
25
|
+
|
26
|
+
begin
|
27
|
+
Resque.inline = true
|
28
|
+
proxy.test_message
|
29
|
+
rescue => e
|
30
|
+
Resque.inline = false
|
31
|
+
raise e
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(message).to have_received(:deliver)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Resque::Plugins::AsyncDeliver::Serializer do
|
5
|
+
def serialize_and_deserialize(*args)
|
6
|
+
serialization = described_class.serialize(*args)
|
7
|
+
json = JSON.dump(serialization)
|
8
|
+
array = JSON.load(json)
|
9
|
+
|
10
|
+
described_class.deserialize(*array)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.serialize' do
|
14
|
+
it 'returns an array with the serialized arguments' do
|
15
|
+
serialization = described_class.serialize(TestMailer, :foo, 'arg')
|
16
|
+
|
17
|
+
expect(serialization).to eq(['TestMailer', 'foo', 'arg'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.deserialize' do
|
22
|
+
it 'returns an array with the deserialized arguments' do
|
23
|
+
deserialization =
|
24
|
+
described_class.deserialize('TestMailer', 'foo', 'arg')
|
25
|
+
|
26
|
+
expect(deserialization).to eq([TestMailer, :foo, 'arg'])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'serializes and deserializes basic objects and queryable models' do
|
31
|
+
args = [
|
32
|
+
TestUser.instance,
|
33
|
+
123,
|
34
|
+
'a string',
|
35
|
+
%q[ an array ],
|
36
|
+
{ 'a' => 'hash' },
|
37
|
+
TestResource.instance
|
38
|
+
]
|
39
|
+
|
40
|
+
deserialization = serialize_and_deserialize(TestMailer, :foo, *args)
|
41
|
+
|
42
|
+
expect(deserialization.shift).to be(TestMailer)
|
43
|
+
expect(deserialization.shift).to be(:foo)
|
44
|
+
expect(deserialization).to eq(args)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'serializes and deserializes queryable models inside arrays' do
|
48
|
+
array = [TestUser.instance]
|
49
|
+
deserialization = serialize_and_deserialize(TestMailer, :foo, array)
|
50
|
+
|
51
|
+
expect(deserialization).to eq([TestMailer, :foo, array])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'serializes and deserializes queryable models inside hashes' do
|
55
|
+
hash = { 'user' => TestUser.instance }
|
56
|
+
deserialization = serialize_and_deserialize(TestMailer, :foo, hash)
|
57
|
+
|
58
|
+
expect(deserialization).to eq([TestMailer, :foo, hash])
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-async_deliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.2.0
|
4
|
+
version: 1.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Philipe Fatio
|
@@ -10,14 +9,12 @@ autorequire:
|
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
|
-
date:
|
14
|
-
default_executable:
|
12
|
+
date: 2014-01-03 00:00:00 Z
|
15
13
|
dependencies:
|
16
14
|
- !ruby/object:Gem::Dependency
|
17
15
|
name: resque
|
18
16
|
prerelease: false
|
19
17
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
18
|
requirements:
|
22
19
|
- - ~>
|
23
20
|
- !ruby/object:Gem::Version
|
@@ -28,46 +25,25 @@ dependencies:
|
|
28
25
|
name: actionmailer
|
29
26
|
prerelease: false
|
30
27
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
-
none: false
|
32
28
|
requirements:
|
33
|
-
- -
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "3"
|
32
|
+
- - <
|
34
33
|
- !ruby/object:Gem::Version
|
35
|
-
version: "
|
34
|
+
version: "5"
|
36
35
|
type: :runtime
|
37
36
|
version_requirements: *id002
|
38
37
|
- !ruby/object:Gem::Dependency
|
39
|
-
name: rspec
|
38
|
+
name: rspec
|
40
39
|
prerelease: false
|
41
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
41
|
requirements:
|
44
42
|
- - ">="
|
45
43
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
44
|
+
version: 3.0.0.beta1
|
47
45
|
type: :development
|
48
46
|
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rspec-expectations
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: "0"
|
58
|
-
type: :development
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: mocha
|
62
|
-
prerelease: false
|
63
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: "0"
|
69
|
-
type: :development
|
70
|
-
version_requirements: *id005
|
71
47
|
description: |
|
72
48
|
This gem makes it possible to send mails asynchronously using Resque by
|
73
49
|
simply rewriting `SomeMailer.some_mail(ar_resource, 1234).deliver` to
|
@@ -88,54 +64,58 @@ files:
|
|
88
64
|
- .gitignore
|
89
65
|
- .rspec
|
90
66
|
- .rvmrc
|
67
|
+
- .travis.yml
|
91
68
|
- Gemfile
|
92
69
|
- README.md
|
93
70
|
- Rakefile
|
94
|
-
- lib/async_deliver
|
95
|
-
- lib/async_deliver
|
96
|
-
- lib/async_deliver/
|
97
|
-
- lib/async_deliver/
|
98
|
-
- lib/async_deliver/
|
99
|
-
- lib/resque
|
71
|
+
- lib/resque/async_deliver.rb
|
72
|
+
- lib/resque/plugins/async_deliver.rb
|
73
|
+
- lib/resque/plugins/async_deliver/action_mailer_extension.rb
|
74
|
+
- lib/resque/plugins/async_deliver/mail_job.rb
|
75
|
+
- lib/resque/plugins/async_deliver/proxy.rb
|
76
|
+
- lib/resque/plugins/async_deliver/railtie.rb
|
77
|
+
- lib/resque/plugins/async_deliver/serializer.rb
|
78
|
+
- lib/resque/plugins/async_deliver/version.rb
|
100
79
|
- resque-async_deliver.gemspec
|
101
|
-
- spec/async_deliver/action_mailer_extension_spec.rb
|
102
|
-
- spec/async_deliver/async_deliver_spec.rb
|
103
|
-
- spec/async_deliver/mail_job_spec.rb
|
104
|
-
- spec/async_deliver/proxy_spec.rb
|
105
80
|
- spec/spec_helper.rb
|
106
81
|
- spec/support.rb
|
107
|
-
|
82
|
+
- spec/unit/action_mailer_spec.rb
|
83
|
+
- spec/unit/async_deliver_spec.rb
|
84
|
+
- spec/unit/mail_job_spec.rb
|
85
|
+
- spec/unit/proxy_spec.rb
|
86
|
+
- spec/unit/serializer_spec.rb
|
108
87
|
homepage: https://github.com/fphilipe/resque-async_deliver
|
109
88
|
licenses: []
|
110
89
|
|
90
|
+
metadata: {}
|
91
|
+
|
111
92
|
post_install_message:
|
112
93
|
rdoc_options: []
|
113
94
|
|
114
95
|
require_paths:
|
115
96
|
- lib
|
116
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
98
|
requirements:
|
119
|
-
-
|
99
|
+
- &id004
|
100
|
+
- ">="
|
120
101
|
- !ruby/object:Gem::Version
|
121
102
|
version: "0"
|
122
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
104
|
requirements:
|
125
|
-
-
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: "0"
|
105
|
+
- *id004
|
128
106
|
requirements: []
|
129
107
|
|
130
108
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 2.1.10
|
132
110
|
signing_key:
|
133
|
-
specification_version:
|
111
|
+
specification_version: 4
|
134
112
|
summary: Deliver mails asynchronously using Resque without explicitly creating a performable job.
|
135
113
|
test_files:
|
136
|
-
- spec/async_deliver/action_mailer_extension_spec.rb
|
137
|
-
- spec/async_deliver/async_deliver_spec.rb
|
138
|
-
- spec/async_deliver/mail_job_spec.rb
|
139
|
-
- spec/async_deliver/proxy_spec.rb
|
140
114
|
- spec/spec_helper.rb
|
141
115
|
- spec/support.rb
|
116
|
+
- spec/unit/action_mailer_spec.rb
|
117
|
+
- spec/unit/async_deliver_spec.rb
|
118
|
+
- spec/unit/mail_job_spec.rb
|
119
|
+
- spec/unit/proxy_spec.rb
|
120
|
+
- spec/unit/serializer_spec.rb
|
121
|
+
has_rdoc:
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'action_mailer'
|
4
|
-
|
5
|
-
module Resque::Plugins::AsyncDeliver
|
6
|
-
module ActionMailerExtension
|
7
|
-
def async_deliver
|
8
|
-
Proxy.new(self)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.initialize
|
13
|
-
ActionMailer::Base.send(:extend, ActionMailerExtension)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
module Resque::Plugins::AsyncDeliver
|
4
|
-
class MailJob
|
5
|
-
@queue = :mail
|
6
|
-
|
7
|
-
def self.perform(*args)
|
8
|
-
mailer = args.shift.constantize
|
9
|
-
method_name = args.shift
|
10
|
-
arguments = []
|
11
|
-
args.each do |a|
|
12
|
-
if a.is_a? Hash and
|
13
|
-
klass = a['async_deliver_class'] || a[:async_deliver_class] and
|
14
|
-
id = a['async_deliver_id'] || a[:async_deliver_id]
|
15
|
-
arguments << klass.constantize.find(id)
|
16
|
-
else
|
17
|
-
arguments << a
|
18
|
-
end
|
19
|
-
end
|
20
|
-
mailer.__send__(method_name, *arguments).deliver
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/async_deliver/proxy.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
module Resque::Plugins::AsyncDeliver
|
4
|
-
class Proxy
|
5
|
-
def initialize(klass)
|
6
|
-
@klass = klass
|
7
|
-
end
|
8
|
-
|
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
|
20
|
-
end
|
21
|
-
Resque.enqueue(MailJob, *arguments)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'rails'
|
4
|
-
|
5
|
-
module Resque::Plugins::AsyncDeliver
|
6
|
-
class Railtie < Rails::Railtie
|
7
|
-
initializer :after_initialize do
|
8
|
-
ActiveSupport.on_load(:action_mailer) do
|
9
|
-
Resque::Plugins::AsyncDeliver.initialize
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/resque-async_deliver.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'resque'
|
4
|
-
|
5
|
-
module Resque
|
6
|
-
module Plugins; end
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'async_deliver/mail_job'
|
10
|
-
require 'async_deliver/proxy'
|
11
|
-
require 'async_deliver/action_mailer_extension'
|
12
|
-
|
13
|
-
if defined? Rails
|
14
|
-
require 'async_deliver/railtie'
|
15
|
-
else
|
16
|
-
Resque::Plugins::AsyncDeliver.initialize
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'a class extended with Resque::Plugins::AsyncDeliver::ActionMailerExtension' do
|
6
|
-
describe '.async_deliver' do
|
7
|
-
before do
|
8
|
-
Resque::Plugins::AsyncDeliver::Proxy.expects(:new).with(TestMailer)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should return a Proxy for the class' do
|
12
|
-
TestMailer.async_deliver
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Resque::Plugins::AsyncDeliver do
|
6
|
-
it 'should extend ActionMailer with Resque::Plugins::AsyncDeliver::ActionMailerExtension' do
|
7
|
-
ActionMailer::Base.should respond_to :async_deliver
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should comply to the Resque plugin guidelines' do
|
11
|
-
expect { Resque::Plugin.lint(Resque::Plugins::AsyncDeliver) }.to_not raise_error
|
12
|
-
end
|
13
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Resque::Plugins::AsyncDeliver::MailJob do
|
6
|
-
describe '.perform' do
|
7
|
-
before do
|
8
|
-
message = mock()
|
9
|
-
message.expects(:deliver)
|
10
|
-
|
11
|
-
TestMailer.expects(:test_message).with(*arguments).returns(message)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should instantiate a mail and deliver it' do
|
15
|
-
Resque::Plugins::AsyncDeliver::MailJob.perform(
|
16
|
-
'TestMailer',
|
17
|
-
:test_message,
|
18
|
-
*serialized_arguments
|
19
|
-
)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Resque::Plugins::AsyncDeliver::Proxy do
|
6
|
-
describe '#method_missing' do
|
7
|
-
let(:proxy) { Resque::Plugins::AsyncDeliver::Proxy.new(TestMailer) }
|
8
|
-
|
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
|
22
|
-
end
|
23
|
-
|
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
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|