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
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YzY1OGRhYjMyNDMzMjI4MTM3OTM5ZmZkNTc2NzRjOTM2NWViNTk1Mg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d0faaf77bf8419f09993b61edb2b44e0bca1a7e
|
4
|
+
data.tar.gz: 200860ed39d65593dc110ddc46927cf8e736dd7e
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NzQ4ODM1NjkwMTgwMmM0MTUzMzRjNDJiMjQ2NTgzMzg1MTc4MWRlMDU3MmM4
|
11
|
-
YmMxZWJjZmM2MjdkZWZjMGVjMWFjMGZiODcyODQwM2U5YjQwZWQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NWVhNTRiZDdhODExMjVhMjgzN2FjMWI3YzIyNjIzYmUyMzg3OGJjNGI3NDNj
|
14
|
-
MzE2OTA4Mzk3NGFhMmY5NzdlZjk2MDdhNWUxNDM4YjM1ODE0MTQzOWU3N2Uz
|
15
|
-
OGNjMDU1MmY3MWY2MTA2Yjk2ZDNmNjFkOTI5ZGIwZmM1M2RhMDU=
|
6
|
+
metadata.gz: 14dbc73e63bbf8b6286a335cf1a2dd4b8c244e0bd2e70925feefe50652230c43b38232ee1672b5b0759488ab35cd0950ca7276eb149d9ef71ab80459950c5ef3
|
7
|
+
data.tar.gz: 32ab6b13c47b1059a826b49009b53c430578acce8c0e7ef48c47ae7c84cf8597122a099a5820b4e254ccb4176f29cd766b38ccfb6f94c42bd2fb505e11314849
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -128,6 +128,10 @@ Older versions of Devise are supported in the [devise_2_1](https://github.com/mh
|
|
128
128
|
|
129
129
|
Please refer to that branch README for further info.
|
130
130
|
|
131
|
+
## Devise >= 4.0
|
132
|
+
|
133
|
+
The current state of this gem does not support Devise 4.0 and up. Have a look into [the Github issue](https://github.com/mhfs/devise-async/issues/94) addressing this. If you are in need for a solution to send Devise messages delayed [a switch to ActiveJob](https://github.com/plataformatec/devise#activejob-integration) is strongly advised.
|
134
|
+
|
131
135
|
## Contributing
|
132
136
|
|
133
137
|
1. Fork it
|
data/devise-async.gemspec
CHANGED
@@ -1,38 +1,31 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
require File.expand_path('../lib/devise/async/version', __FILE__)
|
3
2
|
|
4
3
|
Gem::Specification.new do |gem|
|
5
|
-
gem.name =
|
4
|
+
gem.name = 'devise-async'
|
6
5
|
gem.version = Devise::Async::VERSION
|
7
6
|
gem.platform = Gem::Platform::RUBY
|
8
|
-
gem.authors = [
|
9
|
-
gem.email = [
|
10
|
-
gem.
|
11
|
-
gem.
|
12
|
-
gem.homepage =
|
13
|
-
gem.license =
|
7
|
+
gem.authors = ['Sebastian Oelke', 'Marcelo Silveira']
|
8
|
+
gem.email = ['dev@soelke.de', 'marcelo@mhfs.com.br']
|
9
|
+
gem.summary = %q{Deliver Devise's emails in the background using ActiveJob.}
|
10
|
+
gem.description = %q{Devise Async provides an easy way to configure Devise to send its emails asynchronously using ActiveJob.}
|
11
|
+
gem.homepage = 'https://github.com/mhfs/devise-async/'
|
12
|
+
gem.license = 'MIT'
|
14
13
|
|
15
14
|
gem.files = `git ls-files`.split($\)
|
16
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
17
|
|
19
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
20
19
|
|
21
20
|
|
22
|
-
gem.
|
21
|
+
gem.add_runtime_dependency 'devise', '>= 4.0'
|
22
|
+
gem.add_runtime_dependency 'activejob', '>= 5.0'
|
23
23
|
|
24
|
-
gem.add_development_dependency
|
25
|
-
gem.add_development_dependency
|
26
|
-
gem.add_development_dependency
|
27
|
-
gem.add_development_dependency
|
28
|
-
gem.add_development_dependency
|
29
|
-
gem.add_development_dependency
|
30
|
-
gem.add_development_dependency
|
31
|
-
gem.add_development_dependency "delayed_job_active_record", "~> 0.3"
|
32
|
-
gem.add_development_dependency "queue_classic", "~> 2.0"
|
33
|
-
gem.add_development_dependency "backburner", "~> 0.4"
|
34
|
-
gem.add_development_dependency "mocha", "~> 0.11"
|
35
|
-
gem.add_development_dependency "torquebox-no-op", "~> 2.3"
|
36
|
-
gem.add_development_dependency "sucker_punch", "~> 1.0.5"
|
37
|
-
gem.add_development_dependency "que", "~> 0.8"
|
24
|
+
gem.add_development_dependency 'activerecord', '>= 5.0'
|
25
|
+
gem.add_development_dependency 'actionpack', '>= 5.0'
|
26
|
+
gem.add_development_dependency 'actionmailer', '>= 5.0'
|
27
|
+
gem.add_development_dependency 'rspec', '~> 3.6'
|
28
|
+
gem.add_development_dependency 'rspec-rails', '~> 3.6'
|
29
|
+
gem.add_development_dependency 'sqlite3', '~> 1.3'
|
30
|
+
gem.add_development_dependency 'pry'
|
38
31
|
end
|
data/lib/devise/async.rb
CHANGED
@@ -1,37 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'devise'
|
2
|
+
require 'devise/async/model'
|
3
|
+
require 'devise/async/version'
|
4
4
|
|
5
5
|
module Devise
|
6
6
|
module Async
|
7
|
-
autoload :Worker, "devise/async/worker"
|
8
|
-
autoload :Backend, "devise/async/backend"
|
9
|
-
autoload :Model, "devise/async/model"
|
10
|
-
|
11
|
-
module Backend
|
12
|
-
autoload :Base, "devise/async/backend/base"
|
13
|
-
autoload :Backburner, "devise/async/backend/backburner"
|
14
|
-
autoload :Resque, "devise/async/backend/resque"
|
15
|
-
autoload :Sidekiq, "devise/async/backend/sidekiq"
|
16
|
-
autoload :DelayedJob, "devise/async/backend/delayed_job"
|
17
|
-
autoload :QueueClassic, "devise/async/backend/queue_classic"
|
18
|
-
autoload :Torquebox, "devise/async/backend/torquebox"
|
19
|
-
autoload :SuckerPunch, "devise/async/backend/sucker_punch"
|
20
|
-
autoload :Que, "devise/async/backend/que"
|
21
|
-
end
|
22
|
-
|
23
|
-
# Defines the queue backend to be used. Resque by default.
|
24
|
-
mattr_accessor :backend
|
25
|
-
@@backend = :resque
|
26
|
-
|
27
|
-
# Defines the queue in which the background job will be enqueued. Default is :mailer.
|
28
|
-
mattr_accessor :queue
|
29
|
-
@@queue = :mailer
|
30
|
-
|
31
|
-
# Defines the priority in which the background job will be enqueued. Defaults to the default of the backend you are using.
|
32
|
-
mattr_accessor :priority
|
33
|
-
@@priority = nil
|
34
|
-
|
35
7
|
# Defines the enabled configuration that if set to false the emails will be sent synchronously
|
36
8
|
mattr_accessor :enabled
|
37
9
|
@@enabled = true
|
@@ -41,8 +13,7 @@ module Devise
|
|
41
13
|
# Example:
|
42
14
|
#
|
43
15
|
# Devise::Async.setup do |config|
|
44
|
-
# config.
|
45
|
-
# config.queue = :my_custom_queue
|
16
|
+
# config.enabled = false
|
46
17
|
# end
|
47
18
|
def self.setup
|
48
19
|
yield self
|
@@ -51,4 +22,4 @@ module Devise
|
|
51
22
|
end
|
52
23
|
|
53
24
|
# Register devise-async model in Devise
|
54
|
-
Devise.add_module(:async, :
|
25
|
+
Devise.add_module(:async, model: 'devise/async/model')
|
data/lib/devise/async/model.rb
CHANGED
@@ -27,31 +27,20 @@ module Devise
|
|
27
27
|
def send_devise_notification(notification, *args)
|
28
28
|
return super unless Devise::Async.enabled
|
29
29
|
|
30
|
-
|
31
|
-
|
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
|
-
|
36
|
-
# If the record is dirty we keep pending notifications to be enqueued
|
37
|
-
# by the callback and avoid before commit job processing.
|
38
|
-
if changed?
|
39
|
-
devise_pending_notifications << [ notification, args ]
|
40
|
-
# If the record isn't dirty (aka has already been saved) enqueue right away
|
41
|
-
# because the callback has already been triggered.
|
30
|
+
if new_record? || changed?
|
31
|
+
devise_pending_notifications << [notification, args]
|
42
32
|
else
|
43
|
-
|
33
|
+
deliver_mail_later(notification, self, args)
|
44
34
|
end
|
45
35
|
end
|
46
36
|
|
47
37
|
# Send all pending notifications.
|
48
38
|
def send_devise_pending_notifications
|
49
39
|
devise_pending_notifications.each do |notification, args|
|
50
|
-
|
51
|
-
# wrong with YAJL.
|
52
|
-
Devise::Async::Worker.enqueue(notification, self.class.name, self.id.to_s, *args)
|
40
|
+
deliver_mail_later(notification, self, args)
|
53
41
|
end
|
54
|
-
|
42
|
+
|
43
|
+
@devise_pending_notifications.clear
|
55
44
|
end
|
56
45
|
|
57
46
|
def devise_pending_notifications
|
@@ -60,20 +49,9 @@ module Devise
|
|
60
49
|
|
61
50
|
private
|
62
51
|
|
63
|
-
def
|
64
|
-
|
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
|
52
|
+
def deliver_mail_later(notification, model, args)
|
53
|
+
devise_mailer.send(notification, model, *args).deliver_later
|
68
54
|
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
|
-
|
77
55
|
end
|
78
56
|
end
|
79
57
|
end
|
data/lib/devise/async/version.rb
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
RSpec.describe Devise::Models::Async do
|
2
|
+
before :each do
|
3
|
+
ActiveJob::Base.queue_adapter = :test
|
4
|
+
end
|
5
|
+
|
6
|
+
context 'with unchanged model' do
|
7
|
+
subject { create_admin }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
subject
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'enqueues notifications immediately when the model did not change' do
|
14
|
+
expect(ActionMailer::DeliveryJob).to have_been_enqueued
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'forwards the correct data to the job' do
|
18
|
+
job_data = ActiveJob::Base.queue_adapter.enqueued_jobs.first[:args]
|
19
|
+
expected_job_data = ['Devise::Mailer', 'confirmation_instructions', subject.send(:confirmation_token)]
|
20
|
+
|
21
|
+
expect(job_data).to include(*expected_job_data)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with changed model' do
|
26
|
+
subject do
|
27
|
+
admin[:username] = "changed_username"
|
28
|
+
admin.send_confirmation_instructions
|
29
|
+
|
30
|
+
admin.send(:devise_pending_notifications)
|
31
|
+
end
|
32
|
+
|
33
|
+
let!(:admin) { create_admin }
|
34
|
+
|
35
|
+
context 'without saving the model' do
|
36
|
+
it 'accumulates a pending notification to be sent after commit' do
|
37
|
+
expect(subject).to eq([
|
38
|
+
[:confirmation_instructions, [admin.send(:confirmation_token), {}]]
|
39
|
+
])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not enqueue another job' do
|
43
|
+
expect {
|
44
|
+
subject
|
45
|
+
}.to_not have_enqueued_job(ActionMailer::DeliveryJob)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with saving the model' do
|
50
|
+
let(:save_admin) { admin.save }
|
51
|
+
|
52
|
+
it 'accumulates a pending notification to be sent after commit' do
|
53
|
+
expect(subject).to eq([
|
54
|
+
[:confirmation_instructions, [admin.send(:confirmation_token), {}]]
|
55
|
+
])
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'does enqueue another job' do
|
59
|
+
subject
|
60
|
+
|
61
|
+
expect {
|
62
|
+
save_admin
|
63
|
+
}.to have_enqueued_job(ActionMailer::DeliveryJob)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'forwards the correct data to the job' do
|
67
|
+
subject
|
68
|
+
save_admin
|
69
|
+
|
70
|
+
job_data = ActiveJob::Base.queue_adapter.enqueued_jobs.first[:args]
|
71
|
+
expected_job_data = ['Devise::Mailer', 'confirmation_instructions', admin.send(:confirmation_token)]
|
72
|
+
|
73
|
+
expect(job_data).to include(*expected_job_data)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when devise async is disabled' do
|
79
|
+
around :each do |example|
|
80
|
+
Devise::Async.enabled = false
|
81
|
+
example.run
|
82
|
+
Devise::Async.enabled = true
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'does not enqueue a job' do
|
86
|
+
expect {
|
87
|
+
create_admin
|
88
|
+
}.to_not have_enqueued_job(ActionMailer::DeliveryJob)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'does not accumulate pending notifications' do
|
92
|
+
expect(create_admin.send(:devise_pending_notifications)).to be_empty
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
RSpec.describe Devise::Async do
|
2
|
+
it 'yields self when setup is called' do
|
3
|
+
described_class.setup { |config| expect(config).to eq(Devise::Async) }
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'stores enabled config' do
|
7
|
+
initial_enabled = described_class.enabled
|
8
|
+
|
9
|
+
described_class.enabled = false
|
10
|
+
expect(described_class.enabled).to eq(false)
|
11
|
+
described_class.enabled = initial_enabled
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require 'devise'
|
4
|
+
require 'devise/async'
|
5
|
+
require 'rails/all'
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
require 'support/rails_app'
|
12
|
+
require 'support/test_helpers'
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.infer_spec_type_from_file_location!
|
16
|
+
config.filter_rails_from_backtrace!
|
17
|
+
|
18
|
+
config.include TestHelpers
|
19
|
+
|
20
|
+
config.before :each do
|
21
|
+
load File.dirname(__FILE__) + '/support/rails_app/db/schema.rb'
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
4
|
+
end
|
5
|
+
|
6
|
+
config.mock_with :rspec do |mocks|
|
7
|
+
mocks.verify_partial_doubles = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
11
|
+
config.filter_run_when_matching :focus
|
12
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
config.warnings = true
|
15
|
+
config.order = :random
|
16
|
+
|
17
|
+
if config.files_to_run.one?
|
18
|
+
config.default_formatter = 'doc'
|
19
|
+
end
|
20
|
+
|
21
|
+
Kernel.srand config.seed
|
22
|
+
end
|
@@ -4,10 +4,11 @@ ActiveRecord::Migration.verbose = false
|
|
4
4
|
module Devise
|
5
5
|
module Async
|
6
6
|
class RailsApp < ::Rails::Application
|
7
|
-
config.root = File.dirname(__FILE__) +
|
7
|
+
config.root = File.dirname(__FILE__) + '/rails_app'
|
8
8
|
config.active_support.deprecation = :log
|
9
|
-
config.action_mailer.default_url_options = { :
|
9
|
+
config.action_mailer.default_url_options = { host: 'localhost:3000' }
|
10
10
|
config.action_mailer.delivery_method = :test
|
11
|
+
config.eager_load = false
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
File without changes
|
File without changes
|