devise-async 0.9.0 → 0.10.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/README.md +17 -2
- data/devise-async.gemspec +6 -3
- data/lib/devise/async.rb +7 -0
- data/lib/devise/async/backend/backburner.rb +25 -0
- data/lib/devise/async/backend/base.rb +26 -4
- data/lib/devise/async/backend/delayed_job.rb +5 -1
- data/lib/devise/async/backend/que.rb +19 -0
- data/lib/devise/async/backend/sucker_punch.rb +23 -0
- data/lib/devise/async/model.rb +23 -0
- data/lib/devise/async/version.rb +1 -1
- data/test/devise/async/backend/backburner_test.rb +33 -0
- data/test/devise/async/backend/base_test.rb +44 -5
- data/test/devise/async/backend/delayed_job_test.rb +13 -1
- data/test/devise/async/backend/que_test.rb +21 -0
- data/test/devise/async/backend/sucker_punch_test.rb +21 -0
- data/test/devise/async/backend_test.rb +8 -0
- data/test/devise/async/model_test.rb +24 -0
- data/test/devise/async/worker_test.rb +21 -0
- data/test/devise/async_test.rb +10 -2
- data/test/test_helper.rb +8 -0
- metadata +103 -20
- checksums.yaml +0 -7
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## 0.10.0-alpha
|
4
|
+
|
5
|
+
* Backburner support (jandudulski)
|
6
|
+
* Sucker Punch support (kmayer)
|
7
|
+
* Que support (marshall-lee)
|
8
|
+
* Handle `deliver_now` in preparation for Rails 5 (barelyknown)
|
9
|
+
* Option to set a priority for DJ and Backburner (mkon)
|
10
|
+
* The locale is remembered before an asynchronous task is run (baschtl)
|
11
|
+
* Fixed a usage of `try` that appeared in connection with Rails 4 (baschtl)
|
12
|
+
|
3
13
|
## 0.9.0
|
4
14
|
|
5
15
|
* Multiple mailers support (baschtl)
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Devise Async
|
1
|
+
# Devise Async
|
2
|
+
|
3
|
+
[![Tag](https://img.shields.io/github/tag/mhfs/devise-async.svg?style=flat-square)](https://github.com/mhfs/devise-async/releases) [![Build Status](https://img.shields.io/travis/mhfs/devise-async.svg?style=flat-square)](https://travis-ci.org/mhfs/devise-async) [![Code Climate](https://img.shields.io/codeclimate/github/mhfs/devise-async.svg?style=flat-square)](https://codeclimate.com/github/mhfs/devise-async)
|
2
4
|
|
3
5
|
Devise Async provides an easy way to configure Devise to send its emails asynchronously using your preferred queuing backend.
|
4
6
|
|
@@ -9,6 +11,9 @@ Supported backends:
|
|
9
11
|
* Delayed::Job
|
10
12
|
* QueueClassic
|
11
13
|
* Torquebox
|
14
|
+
* Backburner
|
15
|
+
* Que
|
16
|
+
* SuckerPunch
|
12
17
|
|
13
18
|
## Installation
|
14
19
|
|
@@ -39,7 +44,7 @@ end
|
|
39
44
|
Set your queuing backend by creating `config/initializers/devise_async.rb`:
|
40
45
|
|
41
46
|
```ruby
|
42
|
-
# Supported options: :resque, :sidekiq, :delayed_job, :queue_classic, :torquebox
|
47
|
+
# Supported options: :resque, :sidekiq, :delayed_job, :queue_classic, :torquebox, :backburner, :que, :sucker_punch
|
43
48
|
Devise::Async.backend = :resque
|
44
49
|
```
|
45
50
|
|
@@ -73,6 +78,16 @@ Defaults to :mailer.
|
|
73
78
|
Devise::Async.queue = :my_custom_queue
|
74
79
|
```
|
75
80
|
|
81
|
+
### Custom priority
|
82
|
+
|
83
|
+
You can specify a custom priority for created background jobs in Devise or Backburner.
|
84
|
+
If no value is specified, jobs will be enqueued with whatever default priority is configured in Devise or Backburner.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
# config/initializers/devise_async.rb
|
88
|
+
Devise::Async.priority = 10
|
89
|
+
```
|
90
|
+
|
76
91
|
### Setup via block
|
77
92
|
|
78
93
|
To avoid repeating `Devise::Async` in the initializer file you can use the block syntax
|
data/devise-async.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/devise/async/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Marcelo Silveira"]
|
6
6
|
gem.email = ["marcelo@mhfs.com.br"]
|
7
|
-
gem.description = %q{Send Devise's emails in background. Supports Resque, Sidekiq, Delayed::Job and
|
8
|
-
gem.summary = %q{Devise Async provides an easy way to configure Devise to send its emails asynchronously using your preferred queuing backend. It supports Resque, Sidekiq, Delayed::Job and
|
7
|
+
gem.description = %q{Send Devise's emails in background. Supports Backburner, Resque, Sidekiq, Delayed::Job, QueueClassic, Que, Sucker Punch and Torquebox.}
|
8
|
+
gem.summary = %q{Devise Async provides an easy way to configure Devise to send its emails asynchronously using your preferred queuing backend. It supports Backburner, Resque, Sidekiq, Delayed::Job, QueueClassic, Que, Sucker Punch and Torquebox.}
|
9
9
|
gem.homepage = "https://github.com/mhfs/devise-async/"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
@@ -22,10 +22,13 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_development_dependency "actionmailer", ">= 3.2"
|
23
23
|
gem.add_development_dependency "sqlite3", "~> 1.3"
|
24
24
|
gem.add_development_dependency "resque", "~> 1.20"
|
25
|
-
gem.add_development_dependency "sidekiq", "~>
|
25
|
+
gem.add_development_dependency "sidekiq", "~> 2.17"
|
26
26
|
gem.add_development_dependency "delayed_job_active_record", "~> 0.3"
|
27
27
|
gem.add_development_dependency "queue_classic", "~> 2.0"
|
28
|
+
gem.add_development_dependency "backburner", "~> 0.4"
|
28
29
|
gem.add_development_dependency "mocha", "~> 0.11"
|
29
30
|
gem.add_development_dependency "minitest", "~> 3.0"
|
30
31
|
gem.add_development_dependency "torquebox-no-op", "~> 2.3"
|
32
|
+
gem.add_development_dependency "sucker_punch", "~> 1.0.5"
|
33
|
+
gem.add_development_dependency "que", "~> 0.8"
|
31
34
|
end
|
data/lib/devise/async.rb
CHANGED
@@ -9,11 +9,14 @@ module Devise
|
|
9
9
|
|
10
10
|
module Backend
|
11
11
|
autoload :Base, "devise/async/backend/base"
|
12
|
+
autoload :Backburner, "devise/async/backend/backburner"
|
12
13
|
autoload :Resque, "devise/async/backend/resque"
|
13
14
|
autoload :Sidekiq, "devise/async/backend/sidekiq"
|
14
15
|
autoload :DelayedJob, "devise/async/backend/delayed_job"
|
15
16
|
autoload :QueueClassic, "devise/async/backend/queue_classic"
|
16
17
|
autoload :Torquebox, "devise/async/backend/torquebox"
|
18
|
+
autoload :SuckerPunch, "devise/async/backend/sucker_punch"
|
19
|
+
autoload :Que, "devise/async/backend/que"
|
17
20
|
end
|
18
21
|
|
19
22
|
# Defines the queue backend to be used. Resque by default.
|
@@ -24,6 +27,10 @@ module Devise
|
|
24
27
|
mattr_accessor :queue
|
25
28
|
@@queue = :mailer
|
26
29
|
|
30
|
+
# Defines the priority in which the background job will be enqueued. Defaults to the default of the backend you are using.
|
31
|
+
mattr_accessor :priority
|
32
|
+
@@priority = nil
|
33
|
+
|
27
34
|
# Defines the enabled configuration that if set to false the emails will be sent synchronously
|
28
35
|
mattr_accessor :enabled
|
29
36
|
@@enabled = true
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Devise
|
2
|
+
module Async
|
3
|
+
module Backend
|
4
|
+
class Backburner < Base
|
5
|
+
|
6
|
+
def self.enqueue(*args)
|
7
|
+
args.unshift(self)
|
8
|
+
::Backburner.enqueue(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.perform(*args)
|
12
|
+
new.perform(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.queue
|
16
|
+
Devise::Async.queue
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.queue_priority
|
20
|
+
Devise::Async.priority.nil? ? ::Backburner.configuration.default_priority : Devise::Async.priority
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -10,17 +10,39 @@ module Devise
|
|
10
10
|
#
|
11
11
|
# It uses `orm_adapter` API to fetch the record in order to enforce
|
12
12
|
# compatibility among diferent ORMs.
|
13
|
+
#
|
14
|
+
# This method is executed within the scope of the locale of
|
15
|
+
# the calling thread.
|
13
16
|
def perform(method, resource_class, resource_id, *args)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
I18n.with_locale locale_from_args(args) do
|
18
|
+
resource = resource_class.constantize.to_adapter.get!(resource_id)
|
19
|
+
args[-1] = args.last.symbolize_keys if args.last.is_a?(Hash)
|
20
|
+
mailer = mailer_class(resource).send(method, resource, *args)
|
21
|
+
mailer.send(deliver_method(mailer))
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
private
|
20
26
|
|
21
27
|
def mailer_class(resource = nil)
|
22
|
-
@mailer_class ||= resource.
|
28
|
+
@mailer_class ||= resource.send(:devise_mailer) || Devise.mailer
|
29
|
+
end
|
30
|
+
|
31
|
+
def locale_from_args(args)
|
32
|
+
args_last = args.last
|
33
|
+
args_last.delete('locale') if args_last.is_a?(Hash)
|
23
34
|
end
|
35
|
+
|
36
|
+
# Use #deliver_now if supported, otherwise falls back to #deliver.
|
37
|
+
# Added in preparation for the planned removal of #deliver in Rails 5.
|
38
|
+
def deliver_method(mailer)
|
39
|
+
if mailer.respond_to?(:deliver_now)
|
40
|
+
:deliver_now
|
41
|
+
else
|
42
|
+
:deliver
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
24
46
|
end
|
25
47
|
end
|
26
48
|
end
|
@@ -3,7 +3,11 @@ module Devise
|
|
3
3
|
module Backend
|
4
4
|
class DelayedJob < Base
|
5
5
|
def self.enqueue(*args)
|
6
|
-
new.delay(:queue => Devise::Async.queue).perform(*args)
|
6
|
+
new.delay(:queue => Devise::Async.queue, :priority => priority).perform(*args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.priority
|
10
|
+
Devise::Async.priority.nil? ? Delayed::Worker.default_priority : Devise::Async.priority
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Devise
|
2
|
+
module Async
|
3
|
+
module Backend
|
4
|
+
class Que < Base
|
5
|
+
class Job < ::Que::Job
|
6
|
+
@queue = Devise::Async.queue
|
7
|
+
|
8
|
+
def run(args)
|
9
|
+
Backend::Que.new.perform(*args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.enqueue(*args)
|
14
|
+
Job.enqueue(args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "sucker_punch"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Async
|
5
|
+
module Backend
|
6
|
+
class SuckerPunch < Base
|
7
|
+
include ::SuckerPunch::Job
|
8
|
+
|
9
|
+
def self.enqueue(*args)
|
10
|
+
new.async.perform(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the connection to the pool after we're done with it
|
14
|
+
# see: https://github.com/brandonhilkert/sucker_punch#usage
|
15
|
+
def perform(method, resource_class, resource_id, *args)
|
16
|
+
ActiveRecord::Base.connection_pool.with_connection do
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/devise/async/model.rb
CHANGED
@@ -27,6 +27,12 @@ module Devise
|
|
27
27
|
def send_devise_notification(notification, *args)
|
28
28
|
return super unless Devise::Async.enabled
|
29
29
|
|
30
|
+
# The current locale has to be remembered until the actual sending
|
31
|
+
# of an email because it is scoped to the current thread. Hence,
|
32
|
+
# using asynchronous mechanisms that use another thread to send an
|
33
|
+
# email the currently used locale will be gone later.
|
34
|
+
args = args_with_current_locale(args)
|
35
|
+
|
30
36
|
# If the record is dirty we keep pending notifications to be enqueued
|
31
37
|
# by the callback and avoid before commit job processing.
|
32
38
|
if changed?
|
@@ -51,6 +57,23 @@ module Devise
|
|
51
57
|
def devise_pending_notifications
|
52
58
|
@devise_pending_notifications ||= []
|
53
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def args_with_current_locale(args)
|
64
|
+
# The default_locale is taken in any case. Hence, the args do not have
|
65
|
+
# to be adapted if default_locale and current locale are equal.
|
66
|
+
args = add_current_locale_to_args(args) if I18n.locale != I18n.default_locale
|
67
|
+
args
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_current_locale_to_args(args)
|
71
|
+
# Devise expects a hash as the last parameter for Mailer methods.
|
72
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
73
|
+
opts['locale'] = I18n.locale
|
74
|
+
args.push(opts)
|
75
|
+
end
|
76
|
+
|
54
77
|
end
|
55
78
|
end
|
56
79
|
end
|
data/lib/devise/async/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Async
|
5
|
+
module Backend
|
6
|
+
describe "Backburner" do
|
7
|
+
it "enqueues job" do
|
8
|
+
::Backburner.expects(:enqueue).with(Backburner, :mailer_method, "User", 123, {})
|
9
|
+
Backburner.enqueue(:mailer_method, "User", 123, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
it "delegates to devise mailer when delivering" do
|
13
|
+
user = create_user
|
14
|
+
ActionMailer::Base.deliveries = []
|
15
|
+
Backend::Backburner.perform(:confirmation_instructions, "User", user.id, {})
|
16
|
+
ActionMailer::Base.deliveries.size.must_equal 1
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".queue_priority" do
|
20
|
+
it "returns the right priority when set" do
|
21
|
+
Devise::Async.priority = 15
|
22
|
+
Backburner.queue_priority.must_equal 15
|
23
|
+
Devise::Async.priority = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns default priority when no priority is set" do
|
27
|
+
Backburner.queue_priority.must_equal ::Backburner.configuration.default_priority
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -3,15 +3,33 @@ require "test_helper"
|
|
3
3
|
module Devise
|
4
4
|
module Async
|
5
5
|
module Backend
|
6
|
+
|
6
7
|
describe "Base" do
|
7
8
|
|
8
|
-
|
9
|
+
before do
|
9
10
|
Devise.mailer = "MyMailer"
|
10
|
-
user
|
11
|
-
|
11
|
+
@user = create_user
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
after do
|
15
|
+
Devise.mailer = "Devise::Mailer"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "delegates to configured mailer" do
|
19
|
+
@mailer_instance = mock(:deliver => true)
|
20
|
+
|
21
|
+
MyMailer.expects(:confirmation_instructions).once.returns(@mailer_instance)
|
22
|
+
Base.new.perform(:confirmation_instructions, "User", @user.id, {})
|
23
|
+
end
|
24
|
+
|
25
|
+
it "executes within the locale scope if a locale is given via args" do
|
26
|
+
I18n.expects(:with_locale).once.with(:de)
|
27
|
+
Base.new.perform(:confirmation_instructions, "User", @user.id, { 'locale' => :de })
|
28
|
+
end
|
29
|
+
|
30
|
+
it "does not execute within the locale scope if no locale is given via args" do
|
31
|
+
I18n.expects(:"locale=").never
|
32
|
+
Base.new.perform(:confirmation_instructions, "User", @user.id, {})
|
15
33
|
end
|
16
34
|
|
17
35
|
it "delegates to model configured mailer" do
|
@@ -22,6 +40,27 @@ module Devise
|
|
22
40
|
Base.new.perform(:confirmation_instructions, "UserWithMailer", user.id, {})
|
23
41
|
end
|
24
42
|
|
43
|
+
describe "the delivery method" do
|
44
|
+
before do
|
45
|
+
Devise.mailer = "MyMailer"
|
46
|
+
@user = create_user
|
47
|
+
end
|
48
|
+
|
49
|
+
it "uses #deliver_now when possible" do
|
50
|
+
mailer_instance = mock(:deliver_now => true)
|
51
|
+
|
52
|
+
MyMailer.expects(:confirmation_instructions).once.returns(mailer_instance)
|
53
|
+
Base.new.perform(:confirmation_instructions, "User", @user.id, {})
|
54
|
+
end
|
55
|
+
|
56
|
+
it "uses #deliver otherwise" do
|
57
|
+
mailer_instance = mock(:deliver => true)
|
58
|
+
|
59
|
+
MyMailer.expects(:confirmation_instructions).once.returns(mailer_instance)
|
60
|
+
Base.new.perform(:confirmation_instructions, "User", @user.id, {})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
25
64
|
after do
|
26
65
|
Devise.mailer = "Devise::Mailer"
|
27
66
|
end
|
@@ -7,7 +7,7 @@ module Devise
|
|
7
7
|
it "enqueues job" do
|
8
8
|
delayed_instance = mock()
|
9
9
|
delayed_instance.expects(:perform).once.with(:mailer_method, "User", 123, {})
|
10
|
-
DelayedJob.any_instance.expects(:delay).once.returns(delayed_instance)
|
10
|
+
DelayedJob.any_instance.expects(:delay).with(:queue => Devise::Async.queue, :priority => DelayedJob.priority).once.returns(delayed_instance)
|
11
11
|
|
12
12
|
DelayedJob.enqueue(:mailer_method, "User", 123, {})
|
13
13
|
end
|
@@ -18,6 +18,18 @@ module Devise
|
|
18
18
|
Backend::DelayedJob.new.perform(:confirmation_instructions, "User", user.id, {})
|
19
19
|
ActionMailer::Base.deliveries.size.must_equal 1
|
20
20
|
end
|
21
|
+
|
22
|
+
describe ".priority" do
|
23
|
+
it "returns it when the priority is set" do
|
24
|
+
Devise::Async.priority = 15
|
25
|
+
DelayedJob.priority.must_equal 15
|
26
|
+
Devise::Async.priority = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns the default DJ priority when the priority is not set it" do
|
30
|
+
DelayedJob.priority.must_equal Delayed::Worker.default_priority
|
31
|
+
end
|
32
|
+
end
|
21
33
|
end
|
22
34
|
end
|
23
35
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Async
|
5
|
+
module Backend
|
6
|
+
describe "Que" do
|
7
|
+
it "enqueues job" do
|
8
|
+
Que::Job.expects(:enqueue).with([:mailer_method, "User", 123, {}])
|
9
|
+
Que.enqueue(:mailer_method, "User", 123, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
it "delegates to devise mailer when delivering" do
|
13
|
+
user = create_user
|
14
|
+
ActionMailer::Base.deliveries = []
|
15
|
+
Backend::Que.enqueue(:confirmation_instructions, "User", user.id, {})
|
16
|
+
ActionMailer::Base.deliveries.size.must_equal 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Async
|
5
|
+
module Backend
|
6
|
+
describe "SuckerPunch" do
|
7
|
+
it "enqueus the job" do
|
8
|
+
SuckerPunch.any_instance.expects(:perform).once.with(:mailer_method, "User", 123, {})
|
9
|
+
SuckerPunch.enqueue(:mailer_method, "User", 123, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
it "delegates to devise mailer when delivering" do
|
13
|
+
user = create_user
|
14
|
+
ActionMailer::Base.deliveries = []
|
15
|
+
SuckerPunch.new.perform(:confirmation_instructions, "User", user.id, {})
|
16
|
+
ActionMailer::Base.deliveries.size.must_equal 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -11,6 +11,10 @@ module Devise
|
|
11
11
|
Backend.for(:sidekiq).must_equal Backend::Sidekiq
|
12
12
|
end
|
13
13
|
|
14
|
+
it "gives backburner as the backend" do
|
15
|
+
Backend.for(:backburner).must_equal Backend::Backburner
|
16
|
+
end
|
17
|
+
|
14
18
|
it "gives delayed job as the backend" do
|
15
19
|
Backend.for(:delayed_job).must_equal Backend::DelayedJob
|
16
20
|
end
|
@@ -19,6 +23,10 @@ module Devise
|
|
19
23
|
Backend.for(:queue_classic).must_equal Backend::QueueClassic
|
20
24
|
end
|
21
25
|
|
26
|
+
it "gives sucker punch as the backend" do
|
27
|
+
Backend.for(:sucker_punch).must_equal Backend::SuckerPunch
|
28
|
+
end
|
29
|
+
|
22
30
|
it "alerts about unsupported backend" do
|
23
31
|
assert_raises ArgumentError do
|
24
32
|
Backend.for(:unsupported_backend)
|
@@ -71,6 +71,30 @@ module Devise
|
|
71
71
|
admin.send(:devise_pending_notifications).must_equal []
|
72
72
|
Worker.expects(:enqueue).never
|
73
73
|
end
|
74
|
+
|
75
|
+
describe "custom locale set" do
|
76
|
+
|
77
|
+
# Set a custom locale
|
78
|
+
before { I18n.locale = :de }
|
79
|
+
|
80
|
+
# locale == nil indicates the usage of the default_locale
|
81
|
+
after { I18n.locale = nil }
|
82
|
+
|
83
|
+
it "should set the current locale to the args" do
|
84
|
+
admin = create_admin
|
85
|
+
Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s, instance_of(String), { 'locale' => :de })
|
86
|
+
admin.send_confirmation_instructions
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "default locale set" do
|
91
|
+
|
92
|
+
it "should not set the current locale to the args" do
|
93
|
+
admin = create_admin
|
94
|
+
Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s, instance_of(String), {})
|
95
|
+
admin.send_confirmation_instructions
|
96
|
+
end
|
97
|
+
end
|
74
98
|
end
|
75
99
|
end
|
76
100
|
end
|
@@ -17,6 +17,13 @@ module Devise
|
|
17
17
|
Worker.enqueue(:mailer_method, "User", 123, {})
|
18
18
|
end
|
19
19
|
|
20
|
+
it "enqueues job using the backburner backend" do
|
21
|
+
Devise::Async.backend = :backburner
|
22
|
+
|
23
|
+
Backend::Backburner.expects(:enqueue).with(:mailer_method, "User", 123, {})
|
24
|
+
Worker.enqueue(:mailer_method, "User", 123, {})
|
25
|
+
end
|
26
|
+
|
20
27
|
it "enqueues job using the delayed job backend" do
|
21
28
|
Devise::Async.backend = :delayed_job
|
22
29
|
|
@@ -30,6 +37,20 @@ module Devise
|
|
30
37
|
Backend::QueueClassic.expects(:enqueue).with(:mailer_method, "User", 123, {})
|
31
38
|
Worker.enqueue(:mailer_method, "User", 123, {})
|
32
39
|
end
|
40
|
+
|
41
|
+
it "enqueues job using the sucker punch backend" do
|
42
|
+
Devise::Async.backend = :sucker_punch
|
43
|
+
|
44
|
+
Backend::SuckerPunch.expects(:enqueue).with(:mailer_method, "User", 123, {})
|
45
|
+
Worker.enqueue(:mailer_method, "User", 123, {})
|
46
|
+
end
|
47
|
+
|
48
|
+
it "enqueues job using the que backend" do
|
49
|
+
Devise::Async.backend = :que
|
50
|
+
|
51
|
+
Backend::Que.expects(:enqueue).with(:mailer_method, "User", 123, {})
|
52
|
+
Worker.enqueue(:mailer_method, "User", 123, {})
|
53
|
+
end
|
33
54
|
end
|
34
55
|
end
|
35
56
|
end
|
data/test/devise/async_test.rb
CHANGED
@@ -2,6 +2,11 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
module Devise
|
4
4
|
describe "Async" do
|
5
|
+
|
6
|
+
after do
|
7
|
+
Async.backend = :resque
|
8
|
+
end
|
9
|
+
|
5
10
|
it "yields self when setup is called" do
|
6
11
|
Async.setup { |config| config.must_equal Async }
|
7
12
|
end
|
@@ -16,8 +21,11 @@ module Devise
|
|
16
21
|
Async.backend.must_equal false
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
Async.
|
24
|
+
it "stores priority config" do
|
25
|
+
Async.priority = 15
|
26
|
+
Async.priority.must_equal 15
|
27
|
+
Async.priority = nil
|
21
28
|
end
|
29
|
+
|
22
30
|
end
|
23
31
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,14 +5,20 @@ require "minitest/spec"
|
|
5
5
|
require "minitest/mock"
|
6
6
|
require "mocha/setup"
|
7
7
|
|
8
|
+
require "action_controller"
|
9
|
+
|
8
10
|
require "devise"
|
9
11
|
require "devise/async"
|
10
12
|
require "rails/all"
|
11
13
|
require "resque"
|
12
14
|
require "sidekiq"
|
15
|
+
require "backburner"
|
13
16
|
require "delayed_job_active_record"
|
14
17
|
require "sidekiq/testing"
|
15
18
|
require "torquebox-no-op"
|
19
|
+
require "sucker_punch/testing/inline"
|
20
|
+
require "que"
|
21
|
+
require "queue_classic"
|
16
22
|
|
17
23
|
require "support/rails_app"
|
18
24
|
require "support/test_helpers"
|
@@ -21,3 +27,5 @@ require "support/my_mailer"
|
|
21
27
|
include TestHelpers
|
22
28
|
|
23
29
|
load File.dirname(__FILE__) + "/support/rails_app/db/schema.rb"
|
30
|
+
|
31
|
+
I18n.enforce_available_locales = false
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1.alpha
|
5
|
+
prerelease: 7
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Marcelo Silveira
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: devise
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,48 +30,55 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: activerecord
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '3.2'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '3.2'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: actionpack
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '3.2'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '3.2'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: actionmailer
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- - '>='
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '3.2'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- - '>='
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '3.2'
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: sqlite3
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
83
|
- - ~>
|
74
84
|
- !ruby/object:Gem::Version
|
@@ -76,6 +86,7 @@ dependencies:
|
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ~>
|
81
92
|
- !ruby/object:Gem::Version
|
@@ -83,6 +94,7 @@ dependencies:
|
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: resque
|
85
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
86
98
|
requirements:
|
87
99
|
- - ~>
|
88
100
|
- !ruby/object:Gem::Version
|
@@ -90,6 +102,7 @@ dependencies:
|
|
90
102
|
type: :development
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
93
106
|
requirements:
|
94
107
|
- - ~>
|
95
108
|
- !ruby/object:Gem::Version
|
@@ -97,20 +110,23 @@ dependencies:
|
|
97
110
|
- !ruby/object:Gem::Dependency
|
98
111
|
name: sidekiq
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
100
114
|
requirements:
|
101
115
|
- - ~>
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '2.17'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
107
122
|
requirements:
|
108
123
|
- - ~>
|
109
124
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
125
|
+
version: '2.17'
|
111
126
|
- !ruby/object:Gem::Dependency
|
112
127
|
name: delayed_job_active_record
|
113
128
|
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
114
130
|
requirements:
|
115
131
|
- - ~>
|
116
132
|
- !ruby/object:Gem::Version
|
@@ -118,6 +134,7 @@ dependencies:
|
|
118
134
|
type: :development
|
119
135
|
prerelease: false
|
120
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
121
138
|
requirements:
|
122
139
|
- - ~>
|
123
140
|
- !ruby/object:Gem::Version
|
@@ -125,6 +142,7 @@ dependencies:
|
|
125
142
|
- !ruby/object:Gem::Dependency
|
126
143
|
name: queue_classic
|
127
144
|
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
128
146
|
requirements:
|
129
147
|
- - ~>
|
130
148
|
- !ruby/object:Gem::Version
|
@@ -132,13 +150,31 @@ dependencies:
|
|
132
150
|
type: :development
|
133
151
|
prerelease: false
|
134
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
135
154
|
requirements:
|
136
155
|
- - ~>
|
137
156
|
- !ruby/object:Gem::Version
|
138
157
|
version: '2.0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: backburner
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.4'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.4'
|
139
174
|
- !ruby/object:Gem::Dependency
|
140
175
|
name: mocha
|
141
176
|
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
142
178
|
requirements:
|
143
179
|
- - ~>
|
144
180
|
- !ruby/object:Gem::Version
|
@@ -146,6 +182,7 @@ dependencies:
|
|
146
182
|
type: :development
|
147
183
|
prerelease: false
|
148
184
|
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
149
186
|
requirements:
|
150
187
|
- - ~>
|
151
188
|
- !ruby/object:Gem::Version
|
@@ -153,6 +190,7 @@ dependencies:
|
|
153
190
|
- !ruby/object:Gem::Dependency
|
154
191
|
name: minitest
|
155
192
|
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
156
194
|
requirements:
|
157
195
|
- - ~>
|
158
196
|
- !ruby/object:Gem::Version
|
@@ -160,6 +198,7 @@ dependencies:
|
|
160
198
|
type: :development
|
161
199
|
prerelease: false
|
162
200
|
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
163
202
|
requirements:
|
164
203
|
- - ~>
|
165
204
|
- !ruby/object:Gem::Version
|
@@ -167,6 +206,7 @@ dependencies:
|
|
167
206
|
- !ruby/object:Gem::Dependency
|
168
207
|
name: torquebox-no-op
|
169
208
|
requirement: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
170
210
|
requirements:
|
171
211
|
- - ~>
|
172
212
|
- !ruby/object:Gem::Version
|
@@ -174,12 +214,45 @@ dependencies:
|
|
174
214
|
type: :development
|
175
215
|
prerelease: false
|
176
216
|
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
177
218
|
requirements:
|
178
219
|
- - ~>
|
179
220
|
- !ruby/object:Gem::Version
|
180
221
|
version: '2.3'
|
181
|
-
|
182
|
-
|
222
|
+
- !ruby/object:Gem::Dependency
|
223
|
+
name: sucker_punch
|
224
|
+
requirement: !ruby/object:Gem::Requirement
|
225
|
+
none: false
|
226
|
+
requirements:
|
227
|
+
- - ~>
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 1.0.5
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
none: false
|
234
|
+
requirements:
|
235
|
+
- - ~>
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: 1.0.5
|
238
|
+
- !ruby/object:Gem::Dependency
|
239
|
+
name: que
|
240
|
+
requirement: !ruby/object:Gem::Requirement
|
241
|
+
none: false
|
242
|
+
requirements:
|
243
|
+
- - ~>
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
version: '0.8'
|
246
|
+
type: :development
|
247
|
+
prerelease: false
|
248
|
+
version_requirements: !ruby/object:Gem::Requirement
|
249
|
+
none: false
|
250
|
+
requirements:
|
251
|
+
- - ~>
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
version: '0.8'
|
254
|
+
description: Send Devise's emails in background. Supports Backburner, Resque, Sidekiq,
|
255
|
+
Delayed::Job, QueueClassic, Que, Sucker Punch and Torquebox.
|
183
256
|
email:
|
184
257
|
- marcelo@mhfs.com.br
|
185
258
|
executables: []
|
@@ -197,20 +270,26 @@ files:
|
|
197
270
|
- lib/devise-async.rb
|
198
271
|
- lib/devise/async.rb
|
199
272
|
- lib/devise/async/backend.rb
|
273
|
+
- lib/devise/async/backend/backburner.rb
|
200
274
|
- lib/devise/async/backend/base.rb
|
201
275
|
- lib/devise/async/backend/delayed_job.rb
|
276
|
+
- lib/devise/async/backend/que.rb
|
202
277
|
- lib/devise/async/backend/queue_classic.rb
|
203
278
|
- lib/devise/async/backend/resque.rb
|
204
279
|
- lib/devise/async/backend/sidekiq.rb
|
280
|
+
- lib/devise/async/backend/sucker_punch.rb
|
205
281
|
- lib/devise/async/backend/torquebox.rb
|
206
282
|
- lib/devise/async/model.rb
|
207
283
|
- lib/devise/async/version.rb
|
208
284
|
- lib/devise/async/worker.rb
|
285
|
+
- test/devise/async/backend/backburner_test.rb
|
209
286
|
- test/devise/async/backend/base_test.rb
|
210
287
|
- test/devise/async/backend/delayed_job_test.rb
|
288
|
+
- test/devise/async/backend/que_test.rb
|
211
289
|
- test/devise/async/backend/queue_classic_test.rb
|
212
290
|
- test/devise/async/backend/resque_test.rb
|
213
291
|
- test/devise/async/backend/sidekiq_test.rb
|
292
|
+
- test/devise/async/backend/sucker_punch_test.rb
|
214
293
|
- test/devise/async/backend/torquebox_test.rb
|
215
294
|
- test/devise/async/backend_test.rb
|
216
295
|
- test/devise/async/model_test.rb
|
@@ -231,35 +310,39 @@ files:
|
|
231
310
|
- test/test_helper.rb
|
232
311
|
homepage: https://github.com/mhfs/devise-async/
|
233
312
|
licenses: []
|
234
|
-
metadata: {}
|
235
313
|
post_install_message:
|
236
314
|
rdoc_options: []
|
237
315
|
require_paths:
|
238
316
|
- lib
|
239
317
|
required_ruby_version: !ruby/object:Gem::Requirement
|
318
|
+
none: false
|
240
319
|
requirements:
|
241
|
-
- - '>='
|
320
|
+
- - ! '>='
|
242
321
|
- !ruby/object:Gem::Version
|
243
322
|
version: '0'
|
244
323
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
324
|
+
none: false
|
245
325
|
requirements:
|
246
|
-
- - '
|
326
|
+
- - ! '>'
|
247
327
|
- !ruby/object:Gem::Version
|
248
|
-
version:
|
328
|
+
version: 1.3.1
|
249
329
|
requirements: []
|
250
330
|
rubyforge_project:
|
251
|
-
rubygems_version:
|
331
|
+
rubygems_version: 1.8.23
|
252
332
|
signing_key:
|
253
|
-
specification_version:
|
333
|
+
specification_version: 3
|
254
334
|
summary: Devise Async provides an easy way to configure Devise to send its emails
|
255
|
-
asynchronously using your preferred queuing backend. It supports
|
256
|
-
Delayed::Job and
|
335
|
+
asynchronously using your preferred queuing backend. It supports Backburner, Resque,
|
336
|
+
Sidekiq, Delayed::Job, QueueClassic, Que, Sucker Punch and Torquebox.
|
257
337
|
test_files:
|
338
|
+
- test/devise/async/backend/backburner_test.rb
|
258
339
|
- test/devise/async/backend/base_test.rb
|
259
340
|
- test/devise/async/backend/delayed_job_test.rb
|
341
|
+
- test/devise/async/backend/que_test.rb
|
260
342
|
- test/devise/async/backend/queue_classic_test.rb
|
261
343
|
- test/devise/async/backend/resque_test.rb
|
262
344
|
- test/devise/async/backend/sidekiq_test.rb
|
345
|
+
- test/devise/async/backend/sucker_punch_test.rb
|
263
346
|
- test/devise/async/backend/torquebox_test.rb
|
264
347
|
- test/devise/async/backend_test.rb
|
265
348
|
- test/devise/async/model_test.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 0bc72ccc5171244615739769bf6b9fca485d6701
|
4
|
-
data.tar.gz: 5ddee310635e35eaa7c892db50eaa5db3ab612dc
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 1bc76ed72a9a0c688cc820eda1089ceb730f46db902047f31c50f6673d0500ad05f382500280d320330a4be85b8941f9d3220a2654c4ed67d539a013ea57be69
|
7
|
-
data.tar.gz: 9091df36bf6efe21894c93828f8f5e64865d72b8c12e4753ffe869c40581b1ebd311c619ca7a7d1b6c6f02cf994c08be5a3d18163fb6ee80a124714052b7381c
|