devise-async 0.10.2 → 1.0.0beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +3 -4
- data/.rspec +2 -0
- data/.travis.yml +4 -5
- data/CHANGELOG.md +4 -1
- data/README.md +4 -0
- data/devise-async.gemspec +17 -24
- data/lib/devise/async.rb +5 -34
- data/lib/devise/async/model.rb +8 -30
- data/lib/devise/async/version.rb +1 -1
- data/spec/devise/async/model_spec.rb +95 -0
- data/spec/devise/async_spec.rb +13 -0
- data/spec/rails_helper.rb +23 -0
- data/spec/spec_helper.rb +22 -0
- data/{test → spec}/support/rails_app.rb +3 -2
- data/{test → spec}/support/rails_app/app/models/admin.rb +0 -0
- data/{test → spec}/support/rails_app/config/database.yml +0 -0
- data/{test → spec}/support/rails_app/config/initializers/devise.rb +0 -1
- data/{test → spec}/support/rails_app/config/routes.rb +1 -1
- data/spec/support/rails_app/db/schema.rb +30 -0
- data/spec/support/test_helpers.rb +19 -0
- metadata +76 -206
- data/lib/devise/async/backend.rb +0 -13
- data/lib/devise/async/backend/backburner.rb +0 -25
- data/lib/devise/async/backend/base.rb +0 -49
- data/lib/devise/async/backend/delayed_job.rb +0 -15
- data/lib/devise/async/backend/que.rb +0 -19
- data/lib/devise/async/backend/queue_classic.rb +0 -20
- data/lib/devise/async/backend/resque.rb +0 -18
- data/lib/devise/async/backend/sidekiq.rb +0 -15
- data/lib/devise/async/backend/sucker_punch.rb +0 -23
- data/lib/devise/async/backend/torquebox.rb +0 -14
- data/lib/devise/async/worker.rb +0 -35
- data/test/devise/async/backend/backburner_test.rb +0 -33
- data/test/devise/async/backend/base_test.rb +0 -70
- data/test/devise/async/backend/delayed_job_test.rb +0 -36
- data/test/devise/async/backend/que_test.rb +0 -21
- data/test/devise/async/backend/queue_classic_test.rb +0 -29
- data/test/devise/async/backend/resque_test.rb +0 -27
- data/test/devise/async/backend/sidekiq_test.rb +0 -27
- data/test/devise/async/backend/sucker_punch_test.rb +0 -21
- data/test/devise/async/backend/torquebox_test.rb +0 -21
- data/test/devise/async/backend_test.rb +0 -37
- data/test/devise/async/model_test.rb +0 -100
- data/test/devise/async/worker_test.rb +0 -56
- data/test/devise/async_test.rb +0 -31
- data/test/support/my_mailer.rb +0 -2
- data/test/support/rails_app/app/models/user.rb +0 -5
- data/test/support/rails_app/app/models/user_with_mailer.rb +0 -6
- data/test/support/rails_app/config/initializers/devise_async.rb +0 -3
- data/test/support/rails_app/db/schema.rb +0 -68
- data/test/support/test_helpers.rb +0 -38
- data/test/test_helper.rb +0 -31
data/lib/devise/async/backend.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Devise
|
2
|
-
module Async
|
3
|
-
module Backend
|
4
|
-
# Gives the desired backend driver class to be used to enqueue
|
5
|
-
# jobs.
|
6
|
-
def self.for(backend)
|
7
|
-
const_get(backend.to_s.camelize)
|
8
|
-
rescue NameError
|
9
|
-
raise ArgumentError, "unsupported backend for devise-async."
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,25 +0,0 @@
|
|
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
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Devise
|
2
|
-
module Async
|
3
|
-
module Backend
|
4
|
-
class Base
|
5
|
-
def self.enqueue(*args)
|
6
|
-
raise NotImplementedError, "Any DeviseAssync::Backend subclass should implement `self.enqueue`."
|
7
|
-
end
|
8
|
-
|
9
|
-
# Loads the resource record and sends the email.
|
10
|
-
#
|
11
|
-
# It uses `orm_adapter` API to fetch the record in order to enforce
|
12
|
-
# compatibility among diferent ORMs.
|
13
|
-
#
|
14
|
-
# This method is executed within the scope of the locale of
|
15
|
-
# the calling thread.
|
16
|
-
def perform(method, resource_class, resource_id, *args)
|
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
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def mailer_class(resource = nil)
|
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)
|
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
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Devise
|
2
|
-
module Async
|
3
|
-
module Backend
|
4
|
-
class DelayedJob < Base
|
5
|
-
def self.enqueue(*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
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,19 +0,0 @@
|
|
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
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require "queue_classic"
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
module Async
|
5
|
-
module Backend
|
6
|
-
class QueueClassic < Base
|
7
|
-
def self.enqueue(method, *args)
|
8
|
-
queue = ::QC::Queue.new(Devise::Async.queue)
|
9
|
-
method = String(method) # QC won't serialize Symbol such as #{method}
|
10
|
-
args.unshift("#{self}.perform", method)
|
11
|
-
queue.enqueue(*args)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.perform(*args)
|
15
|
-
new.perform(*args)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Devise
|
2
|
-
module Async
|
3
|
-
module Backend
|
4
|
-
class Resque < Base
|
5
|
-
@queue = Devise::Async.queue
|
6
|
-
|
7
|
-
def self.enqueue(*args)
|
8
|
-
args.unshift(self)
|
9
|
-
::Resque.enqueue(*args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.perform(*args)
|
13
|
-
new.perform(*args)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Devise
|
2
|
-
module Async
|
3
|
-
module Backend
|
4
|
-
class Torquebox < Base
|
5
|
-
include ::TorqueBox::Messaging::Backgroundable
|
6
|
-
always_background :perform
|
7
|
-
|
8
|
-
def self.enqueue(*args)
|
9
|
-
new.perform(*args) # using always_background
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/devise/async/worker.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Devise
|
2
|
-
module Async
|
3
|
-
class Worker
|
4
|
-
class << self
|
5
|
-
|
6
|
-
# Used is the internal interface for devise-async to enqueue notifications
|
7
|
-
# to the desired backend.
|
8
|
-
def enqueue(method, resource_class, resource_id, *args)
|
9
|
-
# convert args to strings and hashes with string keys before passing to backend
|
10
|
-
args = stringify_args args
|
11
|
-
backend_class.enqueue(method, resource_class, resource_id, *args)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def stringify_args(args)
|
17
|
-
args.map do |a|
|
18
|
-
case a
|
19
|
-
when Hash
|
20
|
-
a.stringify_keys
|
21
|
-
when Symbol
|
22
|
-
a.to_s
|
23
|
-
else
|
24
|
-
a
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def backend_class
|
30
|
-
Backend.for(Devise::Async.backend)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,33 +0,0 @@
|
|
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
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
module Async
|
5
|
-
module Backend
|
6
|
-
|
7
|
-
describe "Base" do
|
8
|
-
|
9
|
-
before do
|
10
|
-
Devise.mailer = "MyMailer"
|
11
|
-
@user = create_user
|
12
|
-
end
|
13
|
-
|
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, {})
|
33
|
-
end
|
34
|
-
|
35
|
-
it "delegates to model configured mailer" do
|
36
|
-
user = create_user_with_mailer
|
37
|
-
mailer_instance = mock(:deliver => true)
|
38
|
-
|
39
|
-
MyMailer.expects(:confirmation_instructions).once.returns(mailer_instance)
|
40
|
-
Base.new.perform(:confirmation_instructions, "UserWithMailer", user.id, {})
|
41
|
-
end
|
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
|
-
|
64
|
-
after do
|
65
|
-
Devise.mailer = "Devise::Mailer"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
module Async
|
5
|
-
module Backend
|
6
|
-
describe "DelayedJob" do
|
7
|
-
it "enqueues job" do
|
8
|
-
delayed_instance = mock()
|
9
|
-
delayed_instance.expects(:perform).once.with(:mailer_method, "User", 123, {})
|
10
|
-
DelayedJob.any_instance.expects(:delay).with(:queue => Devise::Async.queue, :priority => DelayedJob.priority).once.returns(delayed_instance)
|
11
|
-
|
12
|
-
DelayedJob.enqueue(:mailer_method, "User", 123, {})
|
13
|
-
end
|
14
|
-
|
15
|
-
it "delegates to devise mailer when delivering" do
|
16
|
-
user = create_user
|
17
|
-
ActionMailer::Base.deliveries = []
|
18
|
-
Backend::DelayedJob.new.perform(:confirmation_instructions, "User", user.id, {})
|
19
|
-
ActionMailer::Base.deliveries.size.must_equal 1
|
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
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
module Async
|
5
|
-
module Backend
|
6
|
-
describe "QueueClassic" do
|
7
|
-
it "enqueues job" do
|
8
|
-
::QC::Queue.any_instance.expects(:enqueue).with(
|
9
|
-
"Devise::Async::Backend::QueueClassic.perform",
|
10
|
-
"mailer_method", "User", 123, {})
|
11
|
-
QueueClassic.enqueue(:mailer_method, "User", 123, {})
|
12
|
-
end
|
13
|
-
|
14
|
-
it "delegates to devise mailer when delivering" do
|
15
|
-
user = create_user
|
16
|
-
ActionMailer::Base.deliveries = []
|
17
|
-
Backend::QueueClassic.perform(:confirmation_instructions, "User", user.id, {})
|
18
|
-
ActionMailer::Base.deliveries.size.must_equal 1
|
19
|
-
end
|
20
|
-
|
21
|
-
it "enqueues to configured queue" do
|
22
|
-
queue = mock(:enqueue => nil)
|
23
|
-
::QC::Queue.expects(:new).with(:custom_queue).once.returns(queue)
|
24
|
-
QueueClassic.enqueue(:mailer_method, "User", 123, {})
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|