active_model_listener 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -1
- data/VERSION +1 -1
- data/active_model_listener.gemspec +1 -1
- data/lib/active_model_listener.rb +8 -16
- data/spec/active_model_listener_spec.rb +8 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
2009-10-26
|
2
2
|
- you no longer have to define all 3 callback methods in callback classes
|
3
|
-
- callback methods are execute without listeners, to prevent recursion
|
3
|
+
- callback methods are execute without listeners, to prevent recursion
|
4
|
+
- inherited subclasses don't get two copies of the callbacks
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -4,24 +4,16 @@ require 'active_model_listener/active_model_listener'
|
|
4
4
|
module WireUpModels
|
5
5
|
|
6
6
|
def self.included(base)
|
7
|
-
base.
|
8
|
-
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def inherited(child)
|
12
|
-
super
|
13
|
-
|
14
|
-
child.after_create do |record|
|
15
|
-
ActiveModelListener.dispatch record, :create
|
16
|
-
end
|
7
|
+
base.after_create do |record|
|
8
|
+
ActiveModelListener.dispatch record, :create
|
9
|
+
end
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
base.after_update do |record|
|
12
|
+
ActiveModelListener.dispatch record, :update
|
13
|
+
end
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
15
|
+
base.after_destroy do |record|
|
16
|
+
ActiveModelListener.dispatch record, :destroy
|
25
17
|
end
|
26
18
|
end
|
27
19
|
|
@@ -28,6 +28,9 @@ describe ActiveModelListener do
|
|
28
28
|
string :title
|
29
29
|
end
|
30
30
|
|
31
|
+
build_model :editorials, :superclass => Article do
|
32
|
+
end
|
33
|
+
|
31
34
|
ActiveModelListener.listeners.clear
|
32
35
|
ActiveModelListener.listeners << FooListener
|
33
36
|
ActiveModelListener.listeners << BarListener
|
@@ -70,6 +73,11 @@ describe ActiveModelListener do
|
|
70
73
|
FooListener.should_receive(:after_create).once
|
71
74
|
Article.create! :title => "foo"
|
72
75
|
end
|
76
|
+
|
77
|
+
it "should not be run twice for inherited models" do
|
78
|
+
FooListener.should_receive(:after_create).once
|
79
|
+
Editorial.create! :title => "foo"
|
80
|
+
end
|
73
81
|
end
|
74
82
|
|
75
83
|
describe "after create" do
|