devise-async 0.3.0 → 0.3.1
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.
- data/CHANGELOG.md +8 -0
- data/lib/devise/async/model.rb +10 -2
- data/lib/devise/async/version.rb +1 -1
- data/test/devise/async/model_test.rb +27 -7
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## 0.3.1
|
4
|
+
|
5
|
+
* Fixes
|
6
|
+
* Do not register after_commit unless ORM supports it
|
7
|
+
* Only enqueue notifications for after_commit if model is dirty
|
8
|
+
|
9
|
+
## 0.3.0
|
10
|
+
|
3
11
|
* Fixes
|
4
12
|
* Added `Devise::Async::Model` to use new devise's after_commit hooks to resolve #6 (only devise >=2.1.1)
|
5
13
|
|
data/lib/devise/async/model.rb
CHANGED
@@ -4,13 +4,21 @@ module Devise
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
after_commit
|
7
|
+
if respond_to?(:after_commit) # AR only
|
8
|
+
after_commit :send_devise_pending_notifications
|
9
|
+
else # mongoid
|
10
|
+
after_save :send_devise_pending_notifications
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
protected
|
11
15
|
|
12
16
|
def send_devise_notification(notification)
|
13
|
-
|
17
|
+
if changed?
|
18
|
+
devise_pending_notifications << notification
|
19
|
+
else
|
20
|
+
Devise::Async::Worker.enqueue(notification, self.class.name, self.id.to_s)
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
def send_devise_pending_notifications
|
data/lib/devise/async/version.rb
CHANGED
@@ -3,18 +3,38 @@ require "test_helper"
|
|
3
3
|
module Devise
|
4
4
|
module Async
|
5
5
|
describe "Model" do
|
6
|
-
it "accumulates notifications to be
|
6
|
+
it "accumulates notifications to be sent after commit on Model creation" do
|
7
|
+
Admin.transaction do
|
8
|
+
admin = create_admin
|
9
|
+
admin.send(:devise_pending_notifications).must_equal [:confirmation_instructions]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "immediately sends notifications when the model has not changed" do
|
7
14
|
admin = create_admin
|
15
|
+
Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s)
|
8
16
|
admin.send_confirmation_instructions
|
9
|
-
|
10
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
it "accumulates notifications to be sent after commit when Model has been changed" do
|
20
|
+
admin = create_admin
|
21
|
+
Admin.transaction do
|
22
|
+
admin[:username] = "changed_username"
|
23
|
+
admin.send_confirmation_instructions
|
24
|
+
admin.send(:devise_pending_notifications).must_equal [:confirmation_instructions]
|
25
|
+
Worker.expects(:enqueue).never # after_commit will not fire without save
|
26
|
+
end
|
11
27
|
end
|
12
28
|
|
13
|
-
it "triggers
|
29
|
+
it "triggers the enqueued notifications on save" do
|
14
30
|
admin = create_admin
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
Admin.transaction do
|
32
|
+
admin[:username] = "changed_username"
|
33
|
+
admin.send_confirmation_instructions
|
34
|
+
admin.send(:devise_pending_notifications).must_equal [:confirmation_instructions]
|
35
|
+
admin.save
|
36
|
+
Worker.expects(:enqueue).with(:confirmation_instructions, "Admin", admin.id.to_s)
|
37
|
+
end
|
18
38
|
end
|
19
39
|
end
|
20
40
|
end
|
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.3.
|
4
|
+
version: 0.3.1
|
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-
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise
|
@@ -232,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
232
232
|
version: '0'
|
233
233
|
segments:
|
234
234
|
- 0
|
235
|
-
hash: -
|
235
|
+
hash: -215577202643201492
|
236
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
237
|
none: false
|
238
238
|
requirements:
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
segments:
|
243
243
|
- 0
|
244
|
-
hash: -
|
244
|
+
hash: -215577202643201492
|
245
245
|
requirements: []
|
246
246
|
rubyforge_project:
|
247
247
|
rubygems_version: 1.8.23
|