resque-async_deliver 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,19 +3,23 @@
3
3
  module Resque::Plugins::AsyncDeliver
4
4
  class Proxy
5
5
  def initialize(klass)
6
- @klass = klass.name
6
+ @klass = klass
7
7
  end
8
8
 
9
- def method_missing(method, *args)
10
- arguments = [ @klass, method ]
11
- args.each do |a|
12
- if a.class < ::ActiveRecord::Base
13
- arguments << { :async_deliver_class => a.class.to_s, :async_deliver_id => a.id }
14
- else
15
- arguments << a
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
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module AsyncDeliver
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
6
6
  end
7
7
  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
- { :async_deliver_class => 'TestUser',
29
- :async_deliver_id => user.id },
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
- before do
12
- Resque.expects(:enqueue).with(
13
- Resque::Plugins::AsyncDeliver::MailJob,
14
- 'TestMailer',
15
- :test_message,
16
- { :async_deliver_class => 'TestUser',
17
- :async_deliver_id => user.id },
18
- 123,
19
- "a string",
20
- %q[ an array ],
21
- { :a => 'hash' },
22
- { :async_deliver_class => 'TestResource',
23
- :async_deliver_id => resource.id }
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
- it 'should enqueue a MailJob in Resque' do
28
- proxy.test_message(
29
- user,
30
- 123,
31
- "a string",
32
- %q[ an array ],
33
- { :a => 'hash' },
34
- resource
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
@@ -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.1.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-07 00:00:00 +02:00
13
+ date: 2011-07-08 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency