soft_deletion 0.1.2 → 0.1.3
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/Gemfile.lock +1 -1
- data/Readme.md +1 -1
- data/gemfiles/rails2.gemfile.lock +1 -1
- data/gemfiles/rails3.gemfile.lock +1 -1
- data/lib/soft_deletion/dependency.rb +2 -2
- data/lib/soft_deletion/version.rb +1 -1
- data/soft_deletion.gemspec +1 -1
- data/test/soft_deletion_test.rb +38 -16
- metadata +5 -5
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -47,7 +47,7 @@ TODO
|
|
47
47
|
|
48
48
|
Author
|
49
49
|
======
|
50
|
-
[
|
50
|
+
[Zendesk](http://zendesk.com)<br/>
|
51
51
|
michael@grosser.it<br/>
|
52
52
|
License: MIT<br/>
|
53
53
|
[](http://travis-ci.org/grosser/soft_deletion)
|
@@ -38,7 +38,7 @@ module SoftDeletion
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def can_soft_delete?
|
41
|
-
|
41
|
+
respond_to? :soft_delete!
|
42
42
|
end
|
43
43
|
|
44
44
|
def klass
|
@@ -50,7 +50,7 @@ module SoftDeletion
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def dependencies
|
53
|
-
Array.wrap(record.send(association_name
|
53
|
+
Array.wrap(record.send(association_name))
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/soft_deletion.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "#{name}/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new name, SoftDeletion::VERSION do |s|
|
6
6
|
s.summary = "Explicit soft deletion for ActiveRecord via deleted_at and default scope."
|
7
|
-
s.authors = ["
|
7
|
+
s.authors = ["Zendesk"]
|
8
8
|
s.email = "michael@grosser.it"
|
9
9
|
s.homepage = "http://github.com/grosser/#{name}"
|
10
10
|
s.files = `git ls-files`.split("\n")
|
data/test/soft_deletion_test.rb
CHANGED
@@ -43,7 +43,8 @@ class Category < ActiveRecord::Base
|
|
43
43
|
has_many :forums, :dependent => :destroy
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
# No association
|
47
|
+
class NACategory < ActiveRecord::Base
|
47
48
|
include SoftDeletion
|
48
49
|
silent_set_table_name 'categories'
|
49
50
|
end
|
@@ -62,6 +63,14 @@ class NDACategory < ActiveRecord::Base
|
|
62
63
|
has_many :forums, :dependent => :destroy, :foreign_key => :category_id
|
63
64
|
end
|
64
65
|
|
66
|
+
# Has ome association
|
67
|
+
class HOACategory < ActiveRecord::Base
|
68
|
+
include SoftDeletion
|
69
|
+
silent_set_table_name 'categories'
|
70
|
+
has_one :forum, :dependent => :destroy, :foreign_key => :category_id
|
71
|
+
end
|
72
|
+
|
73
|
+
|
65
74
|
def clear_callbacks(model, callback)
|
66
75
|
if ActiveRecord::VERSION::MAJOR > 2
|
67
76
|
model.define_callbacks callback
|
@@ -83,6 +92,22 @@ class SoftDeletionTest < ActiveSupport::TestCase
|
|
83
92
|
assert !resource.deleted?
|
84
93
|
end
|
85
94
|
|
95
|
+
def self.successfully_soft_deletes
|
96
|
+
context 'successfully soft deleted' do
|
97
|
+
setup do
|
98
|
+
@category.soft_delete!
|
99
|
+
end
|
100
|
+
|
101
|
+
should 'mark itself as deleted' do
|
102
|
+
assert_deleted @category
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'soft delete its dependent associations' do
|
106
|
+
assert_deleted @forum
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
86
111
|
setup do
|
87
112
|
clear_callbacks Category, :soft_delete
|
88
113
|
end
|
@@ -113,7 +138,7 @@ class SoftDeletionTest < ActiveSupport::TestCase
|
|
113
138
|
|
114
139
|
context 'without dependent associations' do
|
115
140
|
should 'only soft-delete itself' do
|
116
|
-
category =
|
141
|
+
category = NACategory.create!
|
117
142
|
category.soft_delete!
|
118
143
|
assert_deleted category
|
119
144
|
end
|
@@ -128,7 +153,16 @@ class SoftDeletionTest < ActiveSupport::TestCase
|
|
128
153
|
end
|
129
154
|
end
|
130
155
|
|
131
|
-
context 'with dependent
|
156
|
+
context 'with dependent has_one association' do
|
157
|
+
setup do
|
158
|
+
@category = HOACategory.create!
|
159
|
+
@forum = @category.create_forum
|
160
|
+
end
|
161
|
+
|
162
|
+
successfully_soft_deletes
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with dependent has_many associations' do
|
132
166
|
setup do
|
133
167
|
@category = Category.create!
|
134
168
|
@forum = @category.forums.create!
|
@@ -149,19 +183,7 @@ class SoftDeletionTest < ActiveSupport::TestCase
|
|
149
183
|
end
|
150
184
|
end
|
151
185
|
|
152
|
-
|
153
|
-
setup do
|
154
|
-
@category.soft_delete!
|
155
|
-
end
|
156
|
-
|
157
|
-
should 'mark itself as deleted' do
|
158
|
-
assert_deleted @category
|
159
|
-
end
|
160
|
-
|
161
|
-
should 'soft delete its dependent associations' do
|
162
|
-
assert_deleted @forum
|
163
|
-
end
|
164
|
-
end
|
186
|
+
successfully_soft_deletes
|
165
187
|
|
166
188
|
context 'being restored from soft deletion' do
|
167
189
|
setup do
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soft_deletion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- Zendesk
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-08 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description:
|