devise-async 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +6 -0
  3. data/Gemfile +1 -1
  4. data/README.md +13 -7
  5. data/devise-async.gemspec +11 -11
  6. data/lib/devise-async.rb +1 -1
  7. data/lib/devise/async.rb +32 -0
  8. data/lib/devise/async/backend.rb +11 -0
  9. data/lib/devise/async/backend/base.rb +16 -0
  10. data/lib/devise/async/backend/delayed_job.rb +11 -0
  11. data/lib/devise/async/backend/resque.rb +18 -0
  12. data/lib/devise/async/backend/sidekiq.rb +15 -0
  13. data/lib/devise/async/proxy.rb +18 -0
  14. data/lib/devise/async/version.rb +5 -0
  15. data/lib/devise/async/worker.rb +15 -0
  16. data/test/devise/async/backend/delayed_job_test.rb +24 -0
  17. data/test/devise/async/backend/resque_test.rb +21 -0
  18. data/test/devise/async/backend/sidekiq_test.rb +21 -0
  19. data/test/devise/async/backend_test.rb +25 -0
  20. data/test/devise/async/proxy_test.rb +13 -0
  21. data/test/devise/async/worker_test.rb +28 -0
  22. data/test/support/{app → rails_app}/app/models/user.rb +0 -0
  23. data/test/support/rails_app/config/database.yml +5 -0
  24. data/test/support/{app → rails_app}/config/initializers/devise.rb +1 -4
  25. data/test/support/{app → rails_app}/config/routes.rb +0 -0
  26. data/test/support/{app → rails_app}/db/schema.rb +0 -0
  27. data/test/test_helper.rb +13 -10
  28. metadata +43 -41
  29. data/lib/devise_async.rb +0 -18
  30. data/lib/devise_async/backend.rb +0 -9
  31. data/lib/devise_async/backend/delayed_job.rb +0 -14
  32. data/lib/devise_async/backend/resque.rb +0 -17
  33. data/lib/devise_async/backend/sidekiq.rb +0 -18
  34. data/lib/devise_async/proxy.rb +0 -16
  35. data/lib/devise_async/version.rb +0 -3
  36. data/lib/devise_async/worker.rb +0 -13
  37. data/test/backend/delayed_job_test.rb +0 -22
  38. data/test/backend/resque_test.rb +0 -19
  39. data/test/backend/sidekiq_test.rb +0 -19
  40. data/test/backend_test.rb +0 -23
  41. data/test/proxy_test.rb +0 -11
  42. data/test/support/app/config/database.yml +0 -6
  43. data/test/worker_test.rb +0 -26
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- test/support/app/log/*
18
+ test/support/rails_app/log/*
19
+ test/support/rails_app/db/*.sqlite3
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - ree
5
+ - 1.9.2
6
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in devise_background.gemspec
3
+ # Specify your gem's dependencies in devise-async.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Devise Async
1
+ # Devise Async [![Build Status](https://secure.travis-ci.org/mhfs/devise-async.png)](http://travis-ci.org/mhfs/devise-async)
2
2
 
3
3
  Devise Async provides an easy way to configure Devise to send its emails asynchronously using your preferred queuing backend.
4
4
 
@@ -12,7 +12,9 @@ Supported backends:
12
12
 
13
13
  Add this line to your application's Gemfile:
14
14
 
15
- gem 'devise-async'
15
+ ```ruby
16
+ gem 'devise-async'
17
+ ```
16
18
 
17
19
  And then execute:
18
20
 
@@ -24,15 +26,19 @@ Or install it yourself as:
24
26
 
25
27
  ## Usage
26
28
 
27
- Set `DeviseAsync::Proxy` as Devise's mailer in `config/initializers/devise.rb`:
29
+ Set `Devise::Async::Proxy` as Devise's mailer in `config/initializers/devise.rb`:
28
30
 
29
- # Configure the class responsible to send e-mails.
30
- config.mailer = "DeviseAsync::Proxy"
31
+ ```ruby
32
+ # Configure the class responsible to send e-mails.
33
+ config.mailer = "Devise::Async::Proxy"
34
+ ```
31
35
 
32
36
  Set your queuing backend by creating `config/initializers/devise_async.rb`:
33
37
 
34
- # Supported options: :resque, :sidekiq, :delayed_job
35
- DeviseAsync.backend = :resque
38
+ ```ruby
39
+ # Supported options: :resque, :sidekiq, :delayed_job
40
+ Devise::Async.backend = :resque
41
+ ```
36
42
 
37
43
  Tip: it defaults to Resque. You don't need to create the initializer if using it.
38
44
 
data/devise-async.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/devise_async/version', __FILE__)
2
+ require File.expand_path('../lib/devise/async/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Marcelo Silveira"]
@@ -13,17 +13,17 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "devise-async"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = DeviseAsync::VERSION
16
+ gem.version = Devise::Async::VERSION
17
17
 
18
- gem.add_dependency "devise"
18
+ gem.add_dependency "devise", ">= 1.1"
19
19
 
20
- gem.add_development_dependency "activerecord", "~> 3.2"
21
- gem.add_development_dependency "actionpack", "~> 3.2"
22
- gem.add_development_dependency "actionmailer", "~> 3.2"
23
- gem.add_development_dependency "mysql2", "~> 0.3"
24
- gem.add_development_dependency "resque", "~> 1.20"
25
- gem.add_development_dependency "sidekiq", "~> 1.2"
20
+ gem.add_development_dependency "activerecord", "~> 3.2"
21
+ gem.add_development_dependency "actionpack", "~> 3.2"
22
+ gem.add_development_dependency "actionmailer", "~> 3.2"
23
+ gem.add_development_dependency "sqlite3", "~> 1.3"
24
+ gem.add_development_dependency "resque", "~> 1.20"
25
+ gem.add_development_dependency "sidekiq", "~> 1.2"
26
26
  gem.add_development_dependency "delayed_job_active_record", "~> 0.3"
27
- gem.add_development_dependency "mocha", "~> 0.11"
28
- gem.add_development_dependency "minitest", "~> 3.0"
27
+ gem.add_development_dependency "mocha", "~> 0.11"
28
+ gem.add_development_dependency "minitest", "~> 3.0"
29
29
  end
data/lib/devise-async.rb CHANGED
@@ -1 +1 @@
1
- require "devise_async"
1
+ require "devise/async"
@@ -0,0 +1,32 @@
1
+ require "active_support/dependencies"
2
+ require "devise/async/version"
3
+
4
+ module Devise
5
+ module Async
6
+ autoload :Proxy, "devise/async/proxy"
7
+ autoload :Worker, "devise/async/worker"
8
+ autoload :Backend, "devise/async/backend"
9
+
10
+ module Backend
11
+ autoload :Base, "devise/async/backend/base"
12
+ autoload :Resque, "devise/async/backend/resque"
13
+ autoload :Sidekiq, "devise/async/backend/sidekiq"
14
+ autoload :DelayedJob, "devise/async/backend/delayed_job"
15
+ end
16
+
17
+ # Defines the queue backend to be used. Resque by default.
18
+ mattr_accessor :backend
19
+ @@backend = :resque
20
+ end
21
+ end
22
+
23
+ # Just to be compatible with first release
24
+ # TODO remove when appropriate
25
+ module DeviseAsync
26
+ class Proxy < Devise::Async::Proxy
27
+ def initialize(method, resource)
28
+ puts "DEPRECATION WARNING: DeviseAsync::Proxy has been deprecated. Please use Devise::Async::Proxy."
29
+ super
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module Devise
2
+ module Async
3
+ module Backend
4
+ def self.for(backend)
5
+ const_get(backend.to_s.camelize)
6
+ rescue NameError
7
+ raise ArgumentError, "unsupported backend for devise-async."
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
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
+ def perform(method, resource_class, resource_id)
10
+ resource = resource_class.constantize.find(resource_id)
11
+ Devise::Mailer.send(method, resource).deliver
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Devise
2
+ module Async
3
+ module Backend
4
+ class DelayedJob < Base
5
+ def self.enqueue(*args)
6
+ new.delay.perform(*args)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Devise
2
+ module Async
3
+ module Backend
4
+ class Resque < Base
5
+ @queue = :mailer
6
+
7
+ def self.enqueue(*args)
8
+ args.unshift(self)
9
+ ::Resque.enqueue(*args)
10
+ end
11
+
12
+ def self.perform(method, resource_class, resource_id)
13
+ new.perform(method, resource_class, resource_id)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Devise
2
+ module Async
3
+ module Backend
4
+ class Sidekiq < Base
5
+ include ::Sidekiq::Worker
6
+
7
+ sidekiq_options :queue => :mailer
8
+
9
+ def self.enqueue(*args)
10
+ perform_async(*args)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Devise
2
+ module Async
3
+ class Proxy
4
+ # catches all devise emails
5
+ def self.method_missing(method, *args, &block)
6
+ new(method, args.first)
7
+ end
8
+
9
+ def initialize(method, resource)
10
+ @method, @resource = method, resource
11
+ end
12
+
13
+ def deliver
14
+ Worker.enqueue(@method, @resource.class.name, @resource.id)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module Async
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Devise
2
+ module Async
3
+ class Worker
4
+ def self.enqueue(method, resource_class, resource_id)
5
+ backend_class.enqueue(method, resource_class, resource_id)
6
+ end
7
+
8
+ private
9
+
10
+ def self.backend_class
11
+ Backend.for(Devise::Async.backend)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
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).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
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ module Devise
4
+ module Async
5
+ module Backend
6
+ describe "Resque" do
7
+ it "enqueues job" do
8
+ ::Resque.expects(:enqueue).with(Resque, :mailer_method, "User", 123)
9
+ Resque.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::Resque.perform(: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 "Sidekiq" do
7
+ it "enqueues job" do
8
+ Sidekiq.expects(:perform_async).with(:mailer_method, "User", 123)
9
+ Sidekiq.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::Sidekiq.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
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ module Devise
4
+ module Async
5
+ describe "Backend" do
6
+ it "gives resque as the backend" do
7
+ Backend.for(:resque).must_equal Backend::Resque
8
+ end
9
+
10
+ it "gives sidekiq as the backend" do
11
+ Backend.for(:sidekiq).must_equal Backend::Sidekiq
12
+ end
13
+
14
+ it "gives delayed job as the backend" do
15
+ Backend.for(:delayed_job).must_equal Backend::DelayedJob
16
+ end
17
+
18
+ it "alerts about unsupported backend" do
19
+ assert_raises ArgumentError do
20
+ Backend.for(:unsupported_backend)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ module Devise
4
+ module Async
5
+ describe "Proxy" do
6
+ it "gets called by devise operations and proxy to worker" do
7
+ user = create_user
8
+ Worker.expects(:enqueue).with(:confirmation_instructions, "User", user.id)
9
+ user.send_confirmation_instructions
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+
3
+ module Devise
4
+ module Async
5
+ describe "Worker" do
6
+ it "enqueues job using the resque backend" do
7
+ Devise::Async.backend = :resque
8
+
9
+ Backend::Resque.expects(:enqueue).with(:mailer_method, "User", 123)
10
+ Worker.enqueue(:mailer_method, "User", 123)
11
+ end
12
+
13
+ it "enqueues job using the sidekiq backend" do
14
+ Devise::Async.backend = :sidekiq
15
+
16
+ Backend::Sidekiq.expects(:enqueue).with(:mailer_method, "User", 123)
17
+ Worker.enqueue(:mailer_method, "User", 123)
18
+ end
19
+
20
+ it "enqueues job using the delayed job backend" do
21
+ Devise::Async.backend = :delayed_job
22
+
23
+ Backend::DelayedJob.expects(:enqueue).with(:mailer_method, "User", 123)
24
+ Worker.enqueue(:mailer_method, "User", 123)
25
+ end
26
+ end
27
+ end
28
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
@@ -7,7 +7,7 @@ Devise.setup do |config|
7
7
  config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
8
8
 
9
9
  # Configure the class responsible to send e-mails.
10
- config.mailer = "DeviseAsync::Proxy"
10
+ config.mailer = "Devise::Async::Proxy"
11
11
 
12
12
  # ==> ORM configuration
13
13
  # Load and configure the ORM. Supports :active_record (default) and
@@ -213,7 +213,4 @@ Devise.setup do |config|
213
213
  # manager.intercept_401 = false
214
214
  # manager.default_strategies(:scope => :user).unshift :some_external_strategy
215
215
  # end
216
-
217
- # FIXME remove as soon as deprecation stops
218
- config.use_salt_as_remember_token = true
219
216
  end
File without changes
File without changes
data/test/test_helper.rb CHANGED
@@ -5,7 +5,7 @@ require "minitest/spec"
5
5
  require "minitest/mock"
6
6
  require "mocha"
7
7
 
8
- require "devise_async"
8
+ require "devise/async"
9
9
  require "rails/all"
10
10
  require "devise"
11
11
  require "resque"
@@ -14,16 +14,19 @@ require "delayed_job_active_record"
14
14
 
15
15
  require "support/helpers"
16
16
 
17
- Devise.mailer = "DeviseAsync::Proxy"
17
+ # Silent schema load output
18
+ ActiveRecord::Migration.verbose = false
18
19
 
19
- module DeviseAsync
20
- class RailsApp < ::Rails::Application
21
- config.root = File.dirname(__FILE__) + "/support/app"
22
- config.active_support.deprecation = :log
23
- config.action_mailer.default_url_options = { :host => "localhost:3000" }
24
- config.action_mailer.delivery_method = :test
20
+ module Devise
21
+ module Async
22
+ class RailsApp < ::Rails::Application
23
+ config.root = File.dirname(__FILE__) + "/support/rails_app"
24
+ config.active_support.deprecation = :log
25
+ config.action_mailer.default_url_options = { :host => "localhost:3000" }
26
+ config.action_mailer.delivery_method = :test
27
+ end
25
28
  end
26
29
  end
27
30
 
28
- DeviseAsync::RailsApp.initialize!
29
- load File.dirname(__FILE__) + "/support/app/db/schema.rb"
31
+ Devise::Async::RailsApp.initialize!
32
+ load File.dirname(__FILE__) + "/support/rails_app/db/schema.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-async
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-14 00:00:00.000000000 Z
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: devise
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '1.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '1.1'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activerecord
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -76,13 +76,13 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3.2'
78
78
  - !ruby/object:Gem::Dependency
79
- name: mysql2
79
+ name: sqlite3
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '0.3'
85
+ version: '1.3'
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '0.3'
93
+ version: '1.3'
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: resque
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -179,34 +179,36 @@ extensions: []
179
179
  extra_rdoc_files: []
180
180
  files:
181
181
  - .gitignore
182
+ - .travis.yml
182
183
  - Gemfile
183
184
  - LICENSE
184
185
  - README.md
185
186
  - Rakefile
186
187
  - devise-async.gemspec
187
188
  - lib/devise-async.rb
188
- - lib/devise_async.rb
189
- - lib/devise_async/backend.rb
190
- - lib/devise_async/backend/delayed_job.rb
191
- - lib/devise_async/backend/resque.rb
192
- - lib/devise_async/backend/sidekiq.rb
193
- - lib/devise_async/proxy.rb
194
- - lib/devise_async/version.rb
195
- - lib/devise_async/worker.rb
196
- - test/backend/delayed_job_test.rb
197
- - test/backend/resque_test.rb
198
- - test/backend/sidekiq_test.rb
199
- - test/backend_test.rb
200
- - test/proxy_test.rb
201
- - test/support/app/app/models/user.rb
202
- - test/support/app/config/database.yml
203
- - test/support/app/config/initializers/devise.rb
204
- - test/support/app/config/routes.rb
205
- - test/support/app/db/schema.rb
206
- - test/support/app/log/development.log
189
+ - lib/devise/async.rb
190
+ - lib/devise/async/backend.rb
191
+ - lib/devise/async/backend/base.rb
192
+ - lib/devise/async/backend/delayed_job.rb
193
+ - lib/devise/async/backend/resque.rb
194
+ - lib/devise/async/backend/sidekiq.rb
195
+ - lib/devise/async/proxy.rb
196
+ - lib/devise/async/version.rb
197
+ - lib/devise/async/worker.rb
198
+ - test/devise/async/backend/delayed_job_test.rb
199
+ - test/devise/async/backend/resque_test.rb
200
+ - test/devise/async/backend/sidekiq_test.rb
201
+ - test/devise/async/backend_test.rb
202
+ - test/devise/async/proxy_test.rb
203
+ - test/devise/async/worker_test.rb
207
204
  - test/support/helpers.rb
205
+ - test/support/rails_app/app/models/user.rb
206
+ - test/support/rails_app/config/database.yml
207
+ - test/support/rails_app/config/initializers/devise.rb
208
+ - test/support/rails_app/config/routes.rb
209
+ - test/support/rails_app/db/schema.rb
210
+ - test/support/rails_app/log/development.log
208
211
  - test/test_helper.rb
209
- - test/worker_test.rb
210
212
  homepage: https://github.com/mhfs/devise-async/
211
213
  licenses: []
212
214
  post_install_message:
@@ -221,7 +223,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
223
  version: '0'
222
224
  segments:
223
225
  - 0
224
- hash: 375512970430548018
226
+ hash: 198489558210198293
225
227
  required_rubygems_version: !ruby/object:Gem::Requirement
226
228
  none: false
227
229
  requirements:
@@ -230,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
232
  version: '0'
231
233
  segments:
232
234
  - 0
233
- hash: 375512970430548018
235
+ hash: 198489558210198293
234
236
  requirements: []
235
237
  rubyforge_project:
236
238
  rubygems_version: 1.8.23
@@ -240,17 +242,17 @@ summary: Devise Async provides an easy way to configure Devise to send its email
240
242
  asynchronously using your preferred queuing backend. It supports Resque, Sidekiq
241
243
  and Delayed::Job.
242
244
  test_files:
243
- - test/backend/delayed_job_test.rb
244
- - test/backend/resque_test.rb
245
- - test/backend/sidekiq_test.rb
246
- - test/backend_test.rb
247
- - test/proxy_test.rb
248
- - test/support/app/app/models/user.rb
249
- - test/support/app/config/database.yml
250
- - test/support/app/config/initializers/devise.rb
251
- - test/support/app/config/routes.rb
252
- - test/support/app/db/schema.rb
253
- - test/support/app/log/development.log
245
+ - test/devise/async/backend/delayed_job_test.rb
246
+ - test/devise/async/backend/resque_test.rb
247
+ - test/devise/async/backend/sidekiq_test.rb
248
+ - test/devise/async/backend_test.rb
249
+ - test/devise/async/proxy_test.rb
250
+ - test/devise/async/worker_test.rb
254
251
  - test/support/helpers.rb
252
+ - test/support/rails_app/app/models/user.rb
253
+ - test/support/rails_app/config/database.yml
254
+ - test/support/rails_app/config/initializers/devise.rb
255
+ - test/support/rails_app/config/routes.rb
256
+ - test/support/rails_app/db/schema.rb
257
+ - test/support/rails_app/log/development.log
255
258
  - test/test_helper.rb
256
- - test/worker_test.rb
data/lib/devise_async.rb DELETED
@@ -1,18 +0,0 @@
1
- require "active_support/dependencies"
2
- require "devise_async/version"
3
-
4
- module DeviseAsync
5
- autoload :Proxy, "devise_async/proxy"
6
- autoload :Worker, "devise_async/worker"
7
- autoload :Backend, "devise_async/backend"
8
-
9
- module Backend
10
- autoload :Resque, "devise_async/backend/resque"
11
- autoload :Sidekiq, "devise_async/backend/sidekiq"
12
- autoload :DelayedJob, "devise_async/backend/delayed_job"
13
- end
14
-
15
- # Defines the queue backend to be used. Resque by default.
16
- mattr_accessor :backend
17
- @@backend = :resque
18
- end
@@ -1,9 +0,0 @@
1
- module DeviseAsync
2
- module Backend
3
- def self.for(backend)
4
- const_get(backend.to_s.camelize)
5
- rescue NameError
6
- raise ArgumentError, "unsupported backend for devise-async."
7
- end
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- module DeviseAsync
2
- module Backend
3
- class DelayedJob
4
- def self.enqueue(*args)
5
- new.delay.perform(*args)
6
- end
7
-
8
- def perform(method, resource_class, resource_id)
9
- resource = resource_class.constantize.find(resource_id)
10
- Devise::Mailer.send(method, resource).deliver
11
- end
12
- end
13
- end
14
- end
@@ -1,17 +0,0 @@
1
- module DeviseAsync
2
- module Backend
3
- class Resque
4
- @queue = :mailer
5
-
6
- def self.enqueue(*args)
7
- args.unshift(self)
8
- ::Resque.enqueue(*args)
9
- end
10
-
11
- def self.perform(method, resource_class, resource_id)
12
- resource = resource_class.constantize.find(resource_id)
13
- Devise::Mailer.send(method, resource).deliver
14
- end
15
- end
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- module DeviseAsync
2
- module Backend
3
- class Sidekiq
4
- include ::Sidekiq::Worker
5
-
6
- sidekiq_options :queue => :mailer
7
-
8
- def self.enqueue(*args)
9
- perform_async(*args)
10
- end
11
-
12
- def perform(method, resource_class, resource_id)
13
- resource = resource_class.constantize.find(resource_id)
14
- Devise::Mailer.send(method, resource).deliver
15
- end
16
- end
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- module DeviseAsync
2
- class Proxy
3
- # catches all devise emails
4
- def self.method_missing(method, *args, &block)
5
- new(method, args.first)
6
- end
7
-
8
- def initialize(method, resource)
9
- @method, @resource = method, resource
10
- end
11
-
12
- def deliver
13
- Worker.enqueue(@method, @resource.class.name, @resource.id)
14
- end
15
- end
16
- end
@@ -1,3 +0,0 @@
1
- module DeviseAsync
2
- VERSION = "0.0.1"
3
- end
@@ -1,13 +0,0 @@
1
- module DeviseAsync
2
- class Worker
3
- def self.enqueue(method, resource_class, resource_id)
4
- backend_class.enqueue(method, resource_class, resource_id)
5
- end
6
-
7
- private
8
-
9
- def self.backend_class
10
- Backend.for(DeviseAsync.backend)
11
- end
12
- end
13
- end
@@ -1,22 +0,0 @@
1
- require "test_helper"
2
-
3
- module DeviseAsync
4
- module Backend
5
- describe "DelayedJob" do
6
- it "enqueues job" do
7
- delayed_instance = mock()
8
- delayed_instance.expects(:perform).once.with(:mailer_method, "User", 123)
9
- DelayedJob.any_instance.expects(:delay).once.returns(delayed_instance)
10
-
11
- DelayedJob.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::DelayedJob.new.perform(:confirmation_instructions, "User", user.id)
18
- ActionMailer::Base.deliveries.size.must_equal 1
19
- end
20
- end
21
- end
22
- end
@@ -1,19 +0,0 @@
1
- require "test_helper"
2
-
3
- module DeviseAsync
4
- module Backend
5
- describe "Resque" do
6
- it "enqueues job" do
7
- ::Resque.expects(:enqueue).with(Resque, :mailer_method, "User", 123)
8
- Resque.enqueue(:mailer_method, "User", 123)
9
- end
10
-
11
- it "delegates to devise mailer when delivering" do
12
- user = create_user
13
- ActionMailer::Base.deliveries = []
14
- Backend::Resque.perform(:confirmation_instructions, "User", user.id)
15
- ActionMailer::Base.deliveries.size.must_equal 1
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- require "test_helper"
2
-
3
- module DeviseAsync
4
- module Backend
5
- describe "Sidekiq" do
6
- it "enqueues job" do
7
- Sidekiq.expects(:perform_async).with(:mailer_method, "User", 123)
8
- Sidekiq.enqueue(:mailer_method, "User", 123)
9
- end
10
-
11
- it "delegates to devise mailer when delivering" do
12
- user = create_user
13
- ActionMailer::Base.deliveries = []
14
- Backend::Sidekiq.new.perform(:confirmation_instructions, "User", user.id)
15
- ActionMailer::Base.deliveries.size.must_equal 1
16
- end
17
- end
18
- end
19
- end
data/test/backend_test.rb DELETED
@@ -1,23 +0,0 @@
1
- require "test_helper"
2
-
3
- module DeviseAsync
4
- describe "Backend" do
5
- it "gives resque as the backend" do
6
- Backend.for(:resque).must_equal Backend::Resque
7
- end
8
-
9
- it "gives sidekiq as the backend" do
10
- Backend.for(:sidekiq).must_equal Backend::Sidekiq
11
- end
12
-
13
- it "gives delayed job as the backend" do
14
- Backend.for(:delayed_job).must_equal Backend::DelayedJob
15
- end
16
-
17
- it "alerts about unsupported backend" do
18
- assert_raises ArgumentError do
19
- Backend.for(:unsupported_backend)
20
- end
21
- end
22
- end
23
- end
data/test/proxy_test.rb DELETED
@@ -1,11 +0,0 @@
1
- require "test_helper"
2
-
3
- module DeviseAsync
4
- describe "Proxy" do
5
- it "gets called by devise operations and proxy to worker" do
6
- user = create_user
7
- Worker.expects(:enqueue).with(:confirmation_instructions, "User", user.id)
8
- user.send_confirmation_instructions
9
- end
10
- end
11
- end
@@ -1,6 +0,0 @@
1
- test:
2
- adapter: mysql2
3
- database: test
4
- username: root
5
- password: 123mudar
6
- host: localhost
data/test/worker_test.rb DELETED
@@ -1,26 +0,0 @@
1
- require "test_helper"
2
-
3
- module DeviseAsync
4
- describe "Worker" do
5
- it "enqueues job using the resque backend" do
6
- DeviseAsync.backend = :resque
7
-
8
- Backend::Resque.expects(:enqueue).with(:mailer_method, "User", 123)
9
- Worker.enqueue(:mailer_method, "User", 123)
10
- end
11
-
12
- it "enqueues job using the sidekiq backend" do
13
- DeviseAsync.backend = :sidekiq
14
-
15
- Backend::Sidekiq.expects(:enqueue).with(:mailer_method, "User", 123)
16
- Worker.enqueue(:mailer_method, "User", 123)
17
- end
18
-
19
- it "enqueues job using the delayed job backend" do
20
- DeviseAsync.backend = :delayed_job
21
-
22
- Backend::DelayedJob.expects(:enqueue).with(:mailer_method, "User", 123)
23
- Worker.enqueue(:mailer_method, "User", 123)
24
- end
25
- end
26
- end