devise-async 0.10.2 → 1.0.0beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +3 -4
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -5
  5. data/CHANGELOG.md +4 -1
  6. data/README.md +4 -0
  7. data/devise-async.gemspec +17 -24
  8. data/lib/devise/async.rb +5 -34
  9. data/lib/devise/async/model.rb +8 -30
  10. data/lib/devise/async/version.rb +1 -1
  11. data/spec/devise/async/model_spec.rb +95 -0
  12. data/spec/devise/async_spec.rb +13 -0
  13. data/spec/rails_helper.rb +23 -0
  14. data/spec/spec_helper.rb +22 -0
  15. data/{test → spec}/support/rails_app.rb +3 -2
  16. data/{test → spec}/support/rails_app/app/models/admin.rb +0 -0
  17. data/{test → spec}/support/rails_app/config/database.yml +0 -0
  18. data/{test → spec}/support/rails_app/config/initializers/devise.rb +0 -1
  19. data/{test → spec}/support/rails_app/config/routes.rb +1 -1
  20. data/spec/support/rails_app/db/schema.rb +30 -0
  21. data/spec/support/test_helpers.rb +19 -0
  22. metadata +76 -206
  23. data/lib/devise/async/backend.rb +0 -13
  24. data/lib/devise/async/backend/backburner.rb +0 -25
  25. data/lib/devise/async/backend/base.rb +0 -49
  26. data/lib/devise/async/backend/delayed_job.rb +0 -15
  27. data/lib/devise/async/backend/que.rb +0 -19
  28. data/lib/devise/async/backend/queue_classic.rb +0 -20
  29. data/lib/devise/async/backend/resque.rb +0 -18
  30. data/lib/devise/async/backend/sidekiq.rb +0 -15
  31. data/lib/devise/async/backend/sucker_punch.rb +0 -23
  32. data/lib/devise/async/backend/torquebox.rb +0 -14
  33. data/lib/devise/async/worker.rb +0 -35
  34. data/test/devise/async/backend/backburner_test.rb +0 -33
  35. data/test/devise/async/backend/base_test.rb +0 -70
  36. data/test/devise/async/backend/delayed_job_test.rb +0 -36
  37. data/test/devise/async/backend/que_test.rb +0 -21
  38. data/test/devise/async/backend/queue_classic_test.rb +0 -29
  39. data/test/devise/async/backend/resque_test.rb +0 -27
  40. data/test/devise/async/backend/sidekiq_test.rb +0 -27
  41. data/test/devise/async/backend/sucker_punch_test.rb +0 -21
  42. data/test/devise/async/backend/torquebox_test.rb +0 -21
  43. data/test/devise/async/backend_test.rb +0 -37
  44. data/test/devise/async/model_test.rb +0 -100
  45. data/test/devise/async/worker_test.rb +0 -56
  46. data/test/devise/async_test.rb +0 -31
  47. data/test/support/my_mailer.rb +0 -2
  48. data/test/support/rails_app/app/models/user.rb +0 -5
  49. data/test/support/rails_app/app/models/user_with_mailer.rb +0 -6
  50. data/test/support/rails_app/config/initializers/devise_async.rb +0 -3
  51. data/test/support/rails_app/db/schema.rb +0 -68
  52. data/test/support/test_helpers.rb +0 -38
  53. data/test/test_helper.rb +0 -31
@@ -1,27 +0,0 @@
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
-
19
- it "enqueues to configured queue" do
20
- expected_size = 1 + ::Resque.size(:custom_queue)
21
- Resque.enqueue(:mailer_method, "User", 123, {})
22
- ::Resque.size(:custom_queue).must_equal expected_size
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
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
-
19
- it "enqueues to configured queue" do
20
- expected_size = 1 + Sidekiq.jobs.size
21
- Sidekiq.enqueue(:mailer_method, "User", 123, {})
22
- Sidekiq.jobs.size.must_equal expected_size
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,21 +0,0 @@
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
@@ -1,21 +0,0 @@
1
- require "test_helper"
2
-
3
- module Devise
4
- module Async
5
- module Backend
6
- describe "Torquebox" do
7
- it "enqueues job" do
8
- Torquebox.any_instance.expects(:perform).with(:mailer_method, "User", 123, {})
9
- Torquebox.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::Torquebox.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
@@ -1,37 +0,0 @@
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 backburner as the backend" do
15
- Backend.for(:backburner).must_equal Backend::Backburner
16
- end
17
-
18
- it "gives delayed job as the backend" do
19
- Backend.for(:delayed_job).must_equal Backend::DelayedJob
20
- end
21
-
22
- it "gives queue classic as the backend" do
23
- Backend.for(:queue_classic).must_equal Backend::QueueClassic
24
- end
25
-
26
- it "gives sucker punch as the backend" do
27
- Backend.for(:sucker_punch).must_equal Backend::SuckerPunch
28
- end
29
-
30
- it "alerts about unsupported backend" do
31
- assert_raises ArgumentError do
32
- Backend.for(:unsupported_backend)
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,100 +0,0 @@
1
- require "test_helper"
2
-
3
- module Devise
4
- module Async
5
- describe "Model" do
6
- it "accumulates notifications to be sent after commit on Model creation" do
7
- Admin.transaction do
8
- admin = create_admin
9
- mailers = admin.send(:devise_pending_notifications) # [:confirmation_instructions, ["RUQUib67wLcCiEyZMwfx", {}]]
10
- mailers.size.must_equal 1
11
-
12
- mailer = mailers.first
13
- mailer.size.must_equal 2
14
- mailer.first.must_equal :confirmation_instructions
15
- mailer.last.must_be_instance_of Array
16
- end
17
- end
18
-
19
- it "immediately sends notifications when the model has not changed" do
20
- admin = create_admin
21
- Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s, instance_of(String), {})
22
- admin.send_confirmation_instructions
23
- end
24
-
25
- it "accumulates notifications to be sent after commit when Model has been changed" do
26
- admin = create_admin
27
- Admin.transaction do
28
- admin[:username] = "changed_username"
29
- admin.send_confirmation_instructions
30
-
31
- mailers = admin.send(:devise_pending_notifications) # [:confirmation_instructions, ["RUQUib67wLcCiEyZMwfx", {}]]
32
- mailers.size.must_equal 1
33
-
34
- mailer = mailers.first
35
- mailer.size.must_equal 2
36
- mailer.first.must_equal :confirmation_instructions
37
- mailer.last.must_be_instance_of Array
38
-
39
- Worker.expects(:enqueue).never # after_commit will not fire without save
40
- end
41
- end
42
-
43
- it "triggers the enqueued notifications on save" do
44
- admin = create_admin
45
- Admin.transaction do
46
- admin[:username] = "changed_username"
47
- admin.send_confirmation_instructions
48
-
49
- mailers = admin.send(:devise_pending_notifications) # [:confirmation_instructions, ["RUQUib67wLcCiEyZMwfx", {}]]
50
- mailers.size.must_equal 1
51
-
52
- mailer = mailers.first
53
- mailer.size.must_equal 2
54
- mailer.first.must_equal :confirmation_instructions
55
- mailer.last.must_be_instance_of Array
56
-
57
- admin.save
58
- Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s, instance_of(String), {})
59
- end
60
- end
61
-
62
- it "should not enqueue a job if the enabled config option is set to false" do
63
- Devise::Async.stubs(:enabled).returns(false)
64
-
65
- # Stubbing the devise's confirmation_instructions
66
- confirmation_email = Object.new
67
- Devise::Mailer.stubs(:confirmation_instructions).returns(confirmation_email)
68
- confirmation_email.stubs(:deliver).returns(true) # Stubbing the email sending process
69
-
70
- admin = create_admin
71
- admin.send(:devise_pending_notifications).must_equal []
72
- Worker.expects(:enqueue).never
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
98
- end
99
- end
100
- end
@@ -1,56 +0,0 @@
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 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
-
27
- it "enqueues job using the delayed job backend" do
28
- Devise::Async.backend = :delayed_job
29
-
30
- Backend::DelayedJob.expects(:enqueue).with(:mailer_method, "User", 123, {})
31
- Worker.enqueue(:mailer_method, "User", 123, {})
32
- end
33
-
34
- it "enqueues job using the queue classic backend" do
35
- Devise::Async.backend = :queue_classic
36
-
37
- Backend::QueueClassic.expects(:enqueue).with(:mailer_method, "User", 123, {})
38
- Worker.enqueue(:mailer_method, "User", 123, {})
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
54
- end
55
- end
56
- end
@@ -1,31 +0,0 @@
1
- require "test_helper"
2
-
3
- module Devise
4
- describe "Async" do
5
-
6
- after do
7
- Async.backend = :resque
8
- end
9
-
10
- it "yields self when setup is called" do
11
- Async.setup { |config| config.must_equal Async }
12
- end
13
-
14
- it "stores backend config" do
15
- Async.backend = :something
16
- Async.backend.must_equal :something
17
- end
18
-
19
- it "stores enabled config" do
20
- Async.backend = false
21
- Async.backend.must_equal false
22
- end
23
-
24
- it "stores priority config" do
25
- Async.priority = 15
26
- Async.priority.must_equal 15
27
- Async.priority = nil
28
- end
29
-
30
- end
31
- end
@@ -1,2 +0,0 @@
1
- class MyMailer < Devise::Mailer
2
- end
@@ -1,5 +0,0 @@
1
- class User < ActiveRecord::Base
2
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
3
- :registerable, :rememberable, :timeoutable,
4
- :trackable, :validatable
5
- end
@@ -1,6 +0,0 @@
1
- class UserWithMailer < User
2
-
3
- def devise_mailer
4
- MyMailer
5
- end
6
- end
@@ -1,3 +0,0 @@
1
- Devise::Async.setup do |config|
2
- config.queue = :custom_queue
3
- end
@@ -1,68 +0,0 @@
1
- ActiveRecord::Schema.define(:version => 1) do
2
- begin
3
- drop_table :users
4
- drop_rable :delayed_jobs
5
- rescue Exception => e
6
- end
7
-
8
- create_table "users", :force => true do |t|
9
- t.string "username"
10
- t.string "facebook_token"
11
- t.string "email", :default => "", :null => false
12
- t.string "unconfirmed_email", :default => ""
13
- t.string "encrypted_password", :limit => 128, :default => "", :null => false
14
- t.string "confirmation_token"
15
- t.datetime "confirmed_at"
16
- t.datetime "confirmation_sent_at"
17
- t.string "reset_password_token"
18
- t.datetime "remember_created_at"
19
- t.integer "sign_in_count", :default => 0
20
- t.datetime "current_sign_in_at"
21
- t.datetime "last_sign_in_at"
22
- t.string "current_sign_in_ip"
23
- t.string "last_sign_in_ip"
24
- t.integer "failed_attempts", :default => 0
25
- t.string "unlock_token"
26
- t.datetime "locked_at"
27
- t.string "authentication_token"
28
- t.datetime "created_at"
29
- t.datetime "updated_at"
30
- end
31
-
32
- create_table "admins", :force => true do |t|
33
- t.string "username"
34
- t.string "facebook_token"
35
- t.string "email", :default => "", :null => false
36
- t.string "unconfirmed_email", :default => ""
37
- t.string "encrypted_password", :limit => 128, :default => "", :null => false
38
- t.string "confirmation_token"
39
- t.datetime "confirmed_at"
40
- t.datetime "confirmation_sent_at"
41
- t.string "reset_password_token"
42
- t.datetime "remember_created_at"
43
- t.integer "sign_in_count", :default => 0
44
- t.datetime "current_sign_in_at"
45
- t.datetime "last_sign_in_at"
46
- t.string "current_sign_in_ip"
47
- t.string "last_sign_in_ip"
48
- t.integer "failed_attempts", :default => 0
49
- t.string "unlock_token"
50
- t.datetime "locked_at"
51
- t.string "authentication_token"
52
- t.datetime "created_at"
53
- t.datetime "updated_at"
54
- end
55
-
56
- create_table :delayed_jobs, :force => true do |table|
57
- table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
58
- table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
59
- table.text :handler # YAML-encoded string of the object that will do work
60
- table.text :last_error # reason for last failure (See Note below)
61
- table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
62
- table.datetime :locked_at # Set when a client is working on this object
63
- table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
64
- table.string :locked_by # Who is working on this object (if locked)
65
- table.string :queue # The name of the queue this job is in
66
- table.timestamps
67
- end
68
- end
@@ -1,38 +0,0 @@
1
- module TestHelpers
2
- def valid_attributes(attributes={})
3
- { :username => "usertest",
4
- :email => generate_unique_email,
5
- :password => '12345678',
6
- :password_confirmation => '12345678' }.update(attributes)
7
- end
8
-
9
- email_count = 0
10
- define_method :generate_unique_email do
11
- email_count += 1
12
- "test#{email_count}@example.com"
13
- end
14
-
15
- def new_user(attributes={})
16
- User.new(valid_attributes(attributes))
17
- end
18
-
19
- def create_user(attributes={})
20
- User.create!(valid_attributes(attributes))
21
- end
22
-
23
- def new_user_with_mailer(attributes={})
24
- UserWithMailer.new(valid_attributes(attributes))
25
- end
26
-
27
- def create_user_with_mailer(attributes={})
28
- UserWithMailer.create!(valid_attributes(attributes))
29
- end
30
-
31
- def new_admin(attributes={})
32
- Admin.new(valid_attributes(attributes))
33
- end
34
-
35
- def create_admin(attributes={})
36
- Admin.create!(valid_attributes(attributes))
37
- end
38
- end