devise-async 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  ## Unreleased
2
2
 
3
+ * Fixes
4
+ * Added `Devise::Async::Model` to use new devise's after_commit hooks to resolve #6 (only devise >=2.1.1)
5
+
6
+ ## 0.2.0
7
+
3
8
  * Enhancements
4
9
  * Added `Devise::Async.queue` option to let configure the queue
5
10
  the jobs will be enqueued to.
data/README.md CHANGED
@@ -26,12 +26,27 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
+ ### Devise >= 2.1.1
30
+
31
+ Include `Devise::Async::Model` to your Devise model
32
+
33
+ ```ruby
34
+ class User < ActiveRecord::Base
35
+ devise :database_authenticatable, :confirmable # etc ...
36
+
37
+ include Devise::Async::Model # should be below call to `devise`
38
+ end
39
+ ```
40
+
41
+ ### Devise < 2.1.1
42
+
29
43
  Set `Devise::Async::Proxy` as Devise's mailer in `config/initializers/devise.rb`:
30
44
 
31
45
  ```ruby
32
46
  # Configure the class responsible to send e-mails.
33
47
  config.mailer = "Devise::Async::Proxy"
34
48
  ```
49
+ ### All
35
50
 
36
51
  Set your queuing backend by creating `config/initializers/devise_async.rb`:
37
52
 
@@ -6,6 +6,7 @@ module Devise
6
6
  autoload :Proxy, "devise/async/proxy"
7
7
  autoload :Worker, "devise/async/worker"
8
8
  autoload :Backend, "devise/async/backend"
9
+ autoload :Model, "devise/async/model"
9
10
 
10
11
  module Backend
11
12
  autoload :Base, "devise/async/backend/base"
@@ -0,0 +1,30 @@
1
+ module Devise
2
+ module Async
3
+ module Model
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ after_commit :send_devise_pending_notifications
8
+ end
9
+
10
+ protected
11
+
12
+ def send_devise_notification(notification)
13
+ devise_pending_notifications << notification
14
+ end
15
+
16
+ def send_devise_pending_notifications
17
+ devise_pending_notifications.each do |notification|
18
+ # Use `id.to_s` to avoid problems with mongoid 2.4.X ids being serialized
19
+ # wrong with YAJL.
20
+ Devise::Async::Worker.enqueue(notification, self.class.name, self.id.to_s)
21
+ end
22
+ @devise_pending_notifications = []
23
+ end
24
+
25
+ def devise_pending_notifications
26
+ @devise_pending_notifications ||= []
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module Async
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ module Devise
4
+ module Async
5
+ describe "Model" do
6
+ it "accumulates notifications to be send after commit" do
7
+ admin = create_admin
8
+ admin.send_confirmation_instructions
9
+ admin.send(:devise_pending_notifications).must_equal [:confirmation_instructions]
10
+ Worker.expects(:enqueue).never
11
+ end
12
+
13
+ it "triggers enqueues the notifications on save" do
14
+ admin = create_admin
15
+ admin.send_confirmation_instructions
16
+ Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s)
17
+ admin.update_attribute(:username, "newusername")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -18,3 +18,11 @@ end
18
18
  def create_user(attributes={})
19
19
  User.create!(valid_attributes(attributes))
20
20
  end
21
+
22
+ def new_admin(attributes={})
23
+ Admin.new(valid_attributes(attributes))
24
+ end
25
+
26
+ def create_admin(attributes={})
27
+ Admin.create!(valid_attributes(attributes))
28
+ end
@@ -0,0 +1,7 @@
1
+ class Admin < ActiveRecord::Base
2
+ devise :database_authenticatable, :confirmable, :lockable, :recoverable,
3
+ :registerable, :rememberable, :timeoutable, :token_authenticatable,
4
+ :trackable, :validatable
5
+
6
+ include Devise::Async::Model
7
+ end
@@ -29,6 +29,30 @@ ActiveRecord::Schema.define(:version => 1) do
29
29
  t.datetime "updated_at"
30
30
  end
31
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
+
32
56
  create_table :delayed_jobs, :force => true do |table|
33
57
  table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
34
58
  table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
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.2.0
4
+ version: 0.3.0
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-06-15 00:00:00.000000000 Z
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: devise
@@ -193,6 +193,7 @@ files:
193
193
  - lib/devise/async/backend/delayed_job.rb
194
194
  - lib/devise/async/backend/resque.rb
195
195
  - lib/devise/async/backend/sidekiq.rb
196
+ - lib/devise/async/model.rb
196
197
  - lib/devise/async/proxy.rb
197
198
  - lib/devise/async/version.rb
198
199
  - lib/devise/async/worker.rb
@@ -201,12 +202,14 @@ files:
201
202
  - test/devise/async/backend/resque_test.rb
202
203
  - test/devise/async/backend/sidekiq_test.rb
203
204
  - test/devise/async/backend_test.rb
205
+ - test/devise/async/model_test.rb
204
206
  - test/devise/async/proxy_test.rb
205
207
  - test/devise/async/worker_test.rb
206
208
  - test/devise/async_test.rb
207
209
  - test/support/helpers.rb
208
210
  - test/support/my_mailer.rb
209
211
  - test/support/rails_app.rb
212
+ - test/support/rails_app/app/models/admin.rb
210
213
  - test/support/rails_app/app/models/user.rb
211
214
  - test/support/rails_app/config/database.yml
212
215
  - test/support/rails_app/config/initializers/devise.rb
@@ -214,7 +217,6 @@ files:
214
217
  - test/support/rails_app/config/routes.rb
215
218
  - test/support/rails_app/db/schema.rb
216
219
  - test/support/rails_app/log/development.log
217
- - test/support/support/rails_app/log/test.log
218
220
  - test/test_helper.rb
219
221
  homepage: https://github.com/mhfs/devise-async/
220
222
  licenses: []
@@ -230,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
232
  version: '0'
231
233
  segments:
232
234
  - 0
233
- hash: -2016895500650412107
235
+ hash: -1160752069777007952
234
236
  required_rubygems_version: !ruby/object:Gem::Requirement
235
237
  none: false
236
238
  requirements:
@@ -239,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
241
  version: '0'
240
242
  segments:
241
243
  - 0
242
- hash: -2016895500650412107
244
+ hash: -1160752069777007952
243
245
  requirements: []
244
246
  rubyforge_project:
245
247
  rubygems_version: 1.8.23
@@ -254,12 +256,14 @@ test_files:
254
256
  - test/devise/async/backend/resque_test.rb
255
257
  - test/devise/async/backend/sidekiq_test.rb
256
258
  - test/devise/async/backend_test.rb
259
+ - test/devise/async/model_test.rb
257
260
  - test/devise/async/proxy_test.rb
258
261
  - test/devise/async/worker_test.rb
259
262
  - test/devise/async_test.rb
260
263
  - test/support/helpers.rb
261
264
  - test/support/my_mailer.rb
262
265
  - test/support/rails_app.rb
266
+ - test/support/rails_app/app/models/admin.rb
263
267
  - test/support/rails_app/app/models/user.rb
264
268
  - test/support/rails_app/config/database.yml
265
269
  - test/support/rails_app/config/initializers/devise.rb
@@ -267,5 +271,4 @@ test_files:
267
271
  - test/support/rails_app/config/routes.rb
268
272
  - test/support/rails_app/db/schema.rb
269
273
  - test/support/rails_app/log/development.log
270
- - test/support/support/rails_app/log/test.log
271
274
  - test/test_helper.rb