soft_destroyable 0.1.5 → 0.1.6
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/Rakefile +0 -14
- data/VERSION +1 -1
- data/lib/soft_destroyable.rb +14 -4
- data/soft_destroyable.gemspec +1 -1
- data/test/dependent_restrict_test.rb +53 -2
- metadata +3 -3
data/Rakefile
CHANGED
@@ -24,17 +24,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
24
24
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
25
|
end
|
26
26
|
|
27
|
-
begin
|
28
|
-
require 'jeweler'
|
29
|
-
Jeweler::Tasks.new do |gem|
|
30
|
-
gem.name = "soft_destroyable"
|
31
|
-
gem.summary = "Rails 3 ActiveRecord compatible soft destroy implementation"
|
32
|
-
gem.description = "Rails 3 ActiveRecord compatible soft destroy implementation supporting dependent associations"
|
33
|
-
gem.email = "rockrep@yahoo.com"
|
34
|
-
gem.homepage = "http://github.com/rockrep/soft_destroyable"
|
35
|
-
gem.authors = ["Michael Kintzer"]
|
36
|
-
end
|
37
|
-
Jeweler::GemcutterTasks.new
|
38
|
-
rescue LoadError
|
39
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
40
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/lib/soft_destroyable.rb
CHANGED
@@ -229,7 +229,7 @@ module SoftDestroyable
|
|
229
229
|
when :has_many
|
230
230
|
restrict_on_non_empty_has_many(reflection, association)
|
231
231
|
when :has_one
|
232
|
-
|
232
|
+
restrict_on_non_nil_has_one(reflection, association)
|
233
233
|
else
|
234
234
|
end
|
235
235
|
end
|
@@ -278,11 +278,21 @@ module SoftDestroyable
|
|
278
278
|
|
279
279
|
def restrict_on_non_empty_has_many(reflection, association)
|
280
280
|
return unless association
|
281
|
-
|
281
|
+
association.each {|assoc_obj|
|
282
|
+
if assoc_obj.respond_to?(:deleted?)
|
283
|
+
raise ActiveRecord::DeleteRestrictionError.new(reflection) if !assoc_obj.deleted?
|
284
|
+
else
|
285
|
+
raise ActiveRecord::DeleteRestrictionError.new(reflection)
|
286
|
+
end
|
287
|
+
}
|
282
288
|
end
|
283
289
|
|
284
|
-
def
|
285
|
-
|
290
|
+
def restrict_on_non_nil_has_one(reflection, association)
|
291
|
+
if association.respond_to?(:deleted?)
|
292
|
+
raise ActiveRecord::DeleteRestrictionError.new(reflection) if !association.nil? && !association.deleted?
|
293
|
+
else
|
294
|
+
raise ActiveRecord::DeleteRestrictionError.new(reflection) if !association.nil?
|
295
|
+
end
|
286
296
|
end
|
287
297
|
|
288
298
|
end
|
data/soft_destroyable.gemspec
CHANGED
@@ -14,6 +14,16 @@ class DependentRestrictTest < Test::Unit::TestCase
|
|
14
14
|
SoftRestrictOne.delete_all
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_destroy_no_restrict_or_soft_restrict_children
|
18
|
+
@fred.destroy
|
19
|
+
assert_equal true, @fred.deleted?
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_destroy_bang_no_restrict_or_soft_restrict_children
|
23
|
+
@fred.destroy!
|
24
|
+
assert_nil Parent.find_by_id(@fred.id)
|
25
|
+
end
|
26
|
+
|
17
27
|
def test_destroy_has_many_restrict_soft_children
|
18
28
|
@fred.soft_restrict_children << pebbles = SoftRestrictChild.new(:name => "pebbles")
|
19
29
|
@fred.soft_restrict_children << bambam = SoftRestrictChild.new(:name => "bambam")
|
@@ -26,6 +36,17 @@ class DependentRestrictTest < Test::Unit::TestCase
|
|
26
36
|
assert_equal false, bambam.reload.deleted?
|
27
37
|
end
|
28
38
|
|
39
|
+
def test_destroy_has_many_restrict_soft_children_which_are_deleted
|
40
|
+
@fred.soft_restrict_children << pebbles = SoftRestrictChild.new(:name => "pebbles")
|
41
|
+
@fred.soft_restrict_children << bambam = SoftRestrictChild.new(:name => "bambam")
|
42
|
+
assert_equal 2, @fred.reload.soft_restrict_children.count
|
43
|
+
pebbles.destroy
|
44
|
+
bambam.destroy
|
45
|
+
assert_equal 0, @fred.soft_restrict_children.not_deleted.count
|
46
|
+
@fred.destroy
|
47
|
+
assert_equal true, @fred.deleted?
|
48
|
+
end
|
49
|
+
|
29
50
|
def test_destroy_has_many_restrict_children
|
30
51
|
@fred.restrict_children << pebbles = RestrictChild.new(:name => "pebbles")
|
31
52
|
@fred.restrict_children << bambam = RestrictChild.new(:name => "bambam")
|
@@ -50,6 +71,17 @@ class DependentRestrictTest < Test::Unit::TestCase
|
|
50
71
|
assert_equal false, bambam.reload.deleted?
|
51
72
|
end
|
52
73
|
|
74
|
+
def test_destroy_bang_has_many_restrict_soft_children_which_are_deleted
|
75
|
+
@fred.soft_restrict_children << pebbles = SoftRestrictChild.new(:name => "pebbles")
|
76
|
+
@fred.soft_restrict_children << bambam = SoftRestrictChild.new(:name => "bambam")
|
77
|
+
assert_equal 2, @fred.reload.soft_restrict_children.count
|
78
|
+
pebbles.destroy
|
79
|
+
bambam.destroy
|
80
|
+
assert_equal 0, @fred.soft_restrict_children.not_deleted.count
|
81
|
+
@fred.destroy!
|
82
|
+
assert_nil Parent.find_by_id(@fred.id)
|
83
|
+
end
|
84
|
+
|
53
85
|
def test_destroy_bang_has_many_restrict_children
|
54
86
|
@fred.restrict_children << pebbles = RestrictChild.new(:name => "pebbles")
|
55
87
|
@fred.restrict_children << bambam = RestrictChild.new(:name => "bambam")
|
@@ -62,7 +94,7 @@ class DependentRestrictTest < Test::Unit::TestCase
|
|
62
94
|
assert_not_nil RestrictChild.find_by_name("bambam")
|
63
95
|
end
|
64
96
|
|
65
|
-
def
|
97
|
+
def test_destroy_has_soft_restrict_ones
|
66
98
|
@fred.soft_restrict_one = SoftRestrictOne.new(:name => "bambam")
|
67
99
|
assert_equal @fred.reload.soft_restrict_one, SoftRestrictOne.where(:name => "bambam", :parent_id => @fred.id).first
|
68
100
|
assert_raise ActiveRecord::DeleteRestrictionError do
|
@@ -72,7 +104,17 @@ class DependentRestrictTest < Test::Unit::TestCase
|
|
72
104
|
assert_not_nil SoftRestrictOne.find_by_name("bambam")
|
73
105
|
end
|
74
106
|
|
75
|
-
def
|
107
|
+
def test_destroy_has_soft_restrict_ones_which_is_deleted
|
108
|
+
@fred.soft_restrict_one = bambam = SoftRestrictOne.new(:name => "bambam")
|
109
|
+
assert_equal @fred.reload.soft_restrict_one, SoftRestrictOne.where(:name => "bambam", :parent_id => @fred.id).first
|
110
|
+
bambam.destroy
|
111
|
+
assert_equal true, @fred.reload.soft_restrict_one.deleted?
|
112
|
+
@fred.destroy
|
113
|
+
assert_equal true, @fred.deleted?
|
114
|
+
assert_not_nil SoftRestrictOne.find_by_name("bambam")
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_destroy_has_restrict_ones
|
76
118
|
@fred.restrict_one = RestrictOne.new(:name => "bambam")
|
77
119
|
assert_equal @fred.reload.restrict_one, RestrictOne.where(:name => "bambam", :parent_id => @fred.id).first
|
78
120
|
assert_raise ActiveRecord::DeleteRestrictionError do
|
@@ -92,6 +134,15 @@ class DependentRestrictTest < Test::Unit::TestCase
|
|
92
134
|
assert_not_nil SoftRestrictOne.find_by_name("bambam")
|
93
135
|
end
|
94
136
|
|
137
|
+
def test_destroy_bang_has_soft_restrict_ones_which_is_deleted
|
138
|
+
@fred.soft_restrict_one = bambam = SoftRestrictOne.new(:name => "bambam")
|
139
|
+
assert_equal @fred.reload.soft_restrict_one, SoftRestrictOne.where(:name => "bambam", :parent_id => @fred.id).first
|
140
|
+
bambam.destroy
|
141
|
+
assert_equal true, @fred.reload.soft_restrict_one.deleted?
|
142
|
+
@fred.destroy!
|
143
|
+
assert_nil Parent.find_by_id(@fred.id)
|
144
|
+
end
|
145
|
+
|
95
146
|
def test_destroy_bang_has_restrict_ones
|
96
147
|
@fred.restrict_one = RestrictOne.new(:name => "bambam")
|
97
148
|
assert_equal @fred.reload.restrict_one, RestrictOne.where(:name => "bambam", :parent_id => @fred.id).first
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soft_destroyable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Kintzer
|