ohm-contrib 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ohm/contrib/callbacks.rb +7 -1
- data/lib/ohm/contrib.rb +1 -1
- data/ohm-contrib.gemspec +2 -2
- data/test/test_ohm_contrib_callbacks.rb +30 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.19
|
@@ -36,7 +36,6 @@ module Ohm
|
|
36
36
|
# end
|
37
37
|
# end
|
38
38
|
#
|
39
|
-
|
40
39
|
module Callbacks
|
41
40
|
def self.included(base)
|
42
41
|
base.extend Macros
|
@@ -157,6 +156,13 @@ module Ohm
|
|
157
156
|
end
|
158
157
|
end
|
159
158
|
|
159
|
+
def delete
|
160
|
+
execute_callback(:before, :delete)
|
161
|
+
super.tap do |is_deleted|
|
162
|
+
execute_callback(:after, :delete) if is_deleted
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
160
166
|
private
|
161
167
|
def execute_callback(position, method)
|
162
168
|
self.class.callbacks[position][method].each do |callback|
|
data/lib/ohm/contrib.rb
CHANGED
data/ohm-contrib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ohm-contrib}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril David"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-28}
|
13
13
|
s.description = %q{Highly decoupled drop-in functionality for Ohm models}
|
14
14
|
s.email = %q{cyx.ucron@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -14,6 +14,9 @@ class OhmContribCallbacksTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
before :save, :do_before_save
|
16
16
|
after :save, :do_after_save
|
17
|
+
|
18
|
+
before :delete, :do_before_delete
|
19
|
+
after :delete, :do_after_delete
|
17
20
|
|
18
21
|
def validate
|
19
22
|
super
|
@@ -36,6 +39,9 @@ class OhmContribCallbacksTest < Test::Unit::TestCase
|
|
36
39
|
def do_after_create() incr(:do_after_create) end
|
37
40
|
def do_before_save() incr(:do_before_save) end
|
38
41
|
def do_after_save() incr(:do_after_save) end
|
42
|
+
def do_before_delete() incr(:do_before_delete) end
|
43
|
+
def do_after_delete() incr(:do_after_delete) end
|
44
|
+
|
39
45
|
|
40
46
|
def incr(action)
|
41
47
|
val = instance_variable_get("@#{ action }")
|
@@ -138,4 +144,27 @@ class OhmContribCallbacksTest < Test::Unit::TestCase
|
|
138
144
|
assert ! @post.did?(:do_after_save)
|
139
145
|
end
|
140
146
|
end
|
141
|
-
|
147
|
+
|
148
|
+
context "on delete" do
|
149
|
+
setup do
|
150
|
+
@post = Post.create(:body => "The Body")
|
151
|
+
@post = Post[@post.id]
|
152
|
+
@post.delete
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
should "call delete related callbacks once" do
|
157
|
+
assert_equal 1, @post.count(:do_before_delete)
|
158
|
+
assert_equal 1, @post.count(:do_after_delete)
|
159
|
+
end
|
160
|
+
|
161
|
+
should "not call all other callbacks" do
|
162
|
+
assert ! @post.did?(:do_before_validate)
|
163
|
+
assert ! @post.did?(:do_after_validate)
|
164
|
+
assert ! @post.did?(:do_before_create)
|
165
|
+
assert ! @post.did?(:do_after_create)
|
166
|
+
assert ! @post.did?(:do_before_save)
|
167
|
+
assert ! @post.did?(:do_after_save)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 19
|
9
|
+
version: 0.0.19
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril David
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-28 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|