mongo_mapper-paranoia 0.0.1 → 0.0.2
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.
@@ -18,7 +18,7 @@ module MongoMapper
|
|
18
18
|
|
19
19
|
module InstanceMethods
|
20
20
|
# Destroys the instance
|
21
|
-
# @see
|
21
|
+
# @see update_attribute
|
22
22
|
def destroy
|
23
23
|
run_callbacks(:destroy) do
|
24
24
|
update_attribute(:deleted_at, Time.now)
|
@@ -31,6 +31,16 @@ module MongoMapper
|
|
31
31
|
self.deleted_at.present?
|
32
32
|
end
|
33
33
|
alias :deleted? :destroyed?
|
34
|
+
|
35
|
+
# Sets the deleted_at attribute to nil, if present
|
36
|
+
# @see update_attribute
|
37
|
+
def ensure_active
|
38
|
+
run_callbacks(:destroy) do
|
39
|
+
update_attribute(:deleted_at, nil)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
alias :undestroy :ensure_active
|
43
|
+
alias :undelete :ensure_active
|
34
44
|
end
|
35
45
|
|
36
46
|
end
|
@@ -24,6 +24,14 @@ describe MongoMapper::Plugins::Paranoia do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
describe '#ensure_active, #undestroy, #undelete' do
|
28
|
+
it 'should be included via the plugin interface' do
|
29
|
+
@paranoid.should respond_to(:ensure_active)
|
30
|
+
@paranoid.should respond_to(:undestroy)
|
31
|
+
@paranoid.should respond_to(:undelete)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
describe '#destroyed?, #deleted?' do
|
28
36
|
it 'should be included via the plugin interface' do
|
29
37
|
@paranoid.should respond_to(:destroyed?)
|
@@ -32,6 +40,39 @@ describe MongoMapper::Plugins::Paranoia do
|
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
43
|
+
context 'When un-destroying instances' do
|
44
|
+
before(:each) do
|
45
|
+
@paranoid = ParanoidByInclude.create!
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'Instance Methods' do
|
49
|
+
describe '#ensure_active' do
|
50
|
+
it 'should remove the deleted_at timestamp, if set' do
|
51
|
+
@paranoid.destroyed?.should be_false
|
52
|
+
@paranoid.destroy
|
53
|
+
@paranoid.destroyed?.should be_true
|
54
|
+
|
55
|
+
@paranoid.ensure_active
|
56
|
+
@paranoid.destroyed?.should be_false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'Persistence' do
|
62
|
+
it 'should no longer be destroyed, when queried from the server' do
|
63
|
+
pid = @paranoid.id
|
64
|
+
@paranoid.destroy
|
65
|
+
persistanoid = ParanoidByInclude.find(pid)
|
66
|
+
persistanoid.destroyed?.should be_true
|
67
|
+
|
68
|
+
@paranoid.ensure_active
|
69
|
+
persistanoid = ParanoidByInclude.find(pid)
|
70
|
+
persistanoid.destroyed?.should be_false
|
71
|
+
persistanoid.deleted_at.should_not be_present
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
35
76
|
context 'When destroying instances' do
|
36
77
|
before(:each) do
|
37
78
|
@paranoid = ParanoidByInclude.create!
|