acts_as_paranoid 0.5.0 → 0.7.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +117 -0
- data/LICENSE +1 -1
- data/README.md +175 -50
- data/lib/acts_as_paranoid.rb +34 -31
- data/lib/acts_as_paranoid/associations.rb +28 -17
- data/lib/acts_as_paranoid/core.rb +144 -53
- data/lib/acts_as_paranoid/relation.rb +2 -0
- data/lib/acts_as_paranoid/validations.rb +8 -65
- data/lib/acts_as_paranoid/version.rb +3 -1
- data/test/test_associations.rb +161 -39
- data/test/test_core.rb +252 -55
- data/test/test_default_scopes.rb +38 -37
- data/test/test_helper.rb +136 -67
- data/test/test_inheritance.rb +5 -3
- data/test/test_relations.rb +29 -21
- data/test/test_validations.rb +10 -7
- metadata +80 -30
- data/lib/acts_as_paranoid/preloader_association.rb +0 -15
- data/test/test_preloader_association.rb +0 -27
data/test/test_inheritance.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
2
4
|
|
3
5
|
class InheritanceTest < ParanoidBaseTest
|
4
6
|
def test_destroy_dependents_with_inheritance
|
5
7
|
has_many_inherited_super_paranoidz = HasManyInheritedSuperParanoidz.new
|
6
8
|
has_many_inherited_super_paranoidz.save
|
7
9
|
has_many_inherited_super_paranoidz.super_paranoidz.create
|
8
|
-
assert_nothing_raised
|
10
|
+
assert_nothing_raised { has_many_inherited_super_paranoidz.destroy }
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_class_instance_variables_are_inherited
|
12
|
-
assert_nothing_raised
|
14
|
+
assert_nothing_raised { InheritedParanoid.paranoid_column }
|
13
15
|
end
|
14
16
|
end
|
data/test/test_relations.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
2
4
|
|
3
5
|
class RelationsTest < ParanoidBaseTest
|
4
6
|
def setup
|
5
7
|
setup_db
|
6
8
|
|
7
|
-
@paranoid_forest_1 = ParanoidForest.create! :
|
8
|
-
@paranoid_forest_2 = ParanoidForest.create! :
|
9
|
-
@paranoid_forest_3 = ParanoidForest.create! :
|
9
|
+
@paranoid_forest_1 = ParanoidForest.create! name: "ParanoidForest #1"
|
10
|
+
@paranoid_forest_2 = ParanoidForest.create! name: "ParanoidForest #2", rainforest: true
|
11
|
+
@paranoid_forest_3 = ParanoidForest.create! name: "ParanoidForest #3", rainforest: true
|
10
12
|
|
11
13
|
assert_equal 3, ParanoidForest.count
|
12
14
|
assert_equal 2, ParanoidForest.rainforest.count
|
13
15
|
|
14
|
-
@paranoid_forest_1.paranoid_trees.create! :
|
15
|
-
@paranoid_forest_1.paranoid_trees.create! :
|
16
|
-
@paranoid_forest_2.paranoid_trees.create! :
|
17
|
-
@paranoid_forest_2.paranoid_trees.create! :
|
16
|
+
@paranoid_forest_1.paranoid_trees.create! name: "ParanoidTree #1"
|
17
|
+
@paranoid_forest_1.paranoid_trees.create! name: "ParanoidTree #2"
|
18
|
+
@paranoid_forest_2.paranoid_trees.create! name: "ParanoidTree #3"
|
19
|
+
@paranoid_forest_2.paranoid_trees.create! name: "ParanoidTree #4"
|
18
20
|
|
19
21
|
assert_equal 4, ParanoidTree.count
|
20
22
|
end
|
@@ -82,36 +84,42 @@ class RelationsTest < ParanoidBaseTest
|
|
82
84
|
|
83
85
|
# destroy_all: through a relation
|
84
86
|
@paranoid_forest_2.paranoid_trees.order(:id).destroy_all
|
85
|
-
assert_equal 0, @paranoid_forest_2.paranoid_trees
|
86
|
-
assert_equal 2, @paranoid_forest_2.paranoid_trees
|
87
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees.count
|
88
|
+
assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
|
87
89
|
end
|
88
90
|
|
89
|
-
def
|
90
|
-
# destroy!: aliased to delete
|
91
|
+
def test_real_removal_through_relation_with_destroy_bang
|
92
|
+
# Relation.destroy!: aliased to delete
|
91
93
|
ParanoidForest.rainforest.destroy!(@paranoid_forest_3)
|
92
94
|
assert_equal 1, ParanoidForest.rainforest.count
|
93
95
|
assert_equal 1, ParanoidForest.rainforest.with_deleted.count
|
94
96
|
assert_equal 0, ParanoidForest.rainforest.only_deleted.count
|
97
|
+
end
|
95
98
|
|
99
|
+
def test_two_step_real_removal_through_relation_with_destroy
|
96
100
|
# destroy: two-step through a relation
|
97
101
|
paranoid_tree = @paranoid_forest_1.paranoid_trees.first
|
98
102
|
@paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree.id)
|
99
103
|
@paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree.id)
|
100
|
-
assert_equal 1, @paranoid_forest_1.paranoid_trees
|
101
|
-
assert_equal 1, @paranoid_forest_1.paranoid_trees
|
102
|
-
assert_equal 0, @paranoid_forest_1.paranoid_trees
|
104
|
+
assert_equal 1, @paranoid_forest_1.paranoid_trees.count
|
105
|
+
assert_equal 1, @paranoid_forest_1.paranoid_trees.with_deleted.count
|
106
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
|
107
|
+
end
|
103
108
|
|
109
|
+
def test_two_step_real_removal_through_relation_with_destroy_all
|
104
110
|
# destroy_all: two-step through a relation
|
105
111
|
@paranoid_forest_1.paranoid_trees.order(:id).destroy_all
|
106
112
|
@paranoid_forest_1.paranoid_trees.only_deleted.destroy_all
|
107
|
-
assert_equal 0, @paranoid_forest_1.paranoid_trees
|
108
|
-
assert_equal 0, @paranoid_forest_1.paranoid_trees
|
109
|
-
assert_equal 0, @paranoid_forest_1.paranoid_trees
|
113
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees.count
|
114
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees.with_deleted.count
|
115
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
|
116
|
+
end
|
110
117
|
|
118
|
+
def test_real_removal_through_relation_with_delete_all_bang
|
111
119
|
# delete_all!: through a relation
|
112
120
|
@paranoid_forest_2.paranoid_trees.order(:id).delete_all!
|
113
|
-
assert_equal 0, @paranoid_forest_2.paranoid_trees
|
114
|
-
assert_equal 0, @paranoid_forest_2.paranoid_trees
|
115
|
-
assert_equal 0, @paranoid_forest_2.paranoid_trees
|
121
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees.count
|
122
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees.with_deleted.count
|
123
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees.only_deleted.count
|
116
124
|
end
|
117
125
|
end
|
data/test/test_validations.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
2
4
|
|
3
5
|
class ValidatesUniquenessTest < ParanoidBaseTest
|
4
6
|
def test_should_include_deleted_by_default
|
5
|
-
ParanoidTime.new(:
|
7
|
+
ParanoidTime.new(name: "paranoid").tap do |record|
|
6
8
|
assert !record.valid?
|
7
9
|
ParanoidTime.first.destroy
|
8
10
|
assert !record.valid?
|
@@ -12,7 +14,8 @@ class ValidatesUniquenessTest < ParanoidBaseTest
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def test_should_validate_without_deleted
|
15
|
-
ParanoidBoolean.new(:
|
17
|
+
ParanoidBoolean.new(name: "paranoid").tap do |record|
|
18
|
+
refute record.valid?
|
16
19
|
ParanoidBoolean.first.destroy
|
17
20
|
assert record.valid?
|
18
21
|
ParanoidBoolean.only_deleted.first.destroy!
|
@@ -21,8 +24,8 @@ class ValidatesUniquenessTest < ParanoidBaseTest
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_models_with_scoped_validations_can_be_multiply_deleted
|
24
|
-
model_a = ParanoidWithScopedValidation.create(:
|
25
|
-
model_b = ParanoidWithScopedValidation.create(:
|
27
|
+
model_a = ParanoidWithScopedValidation.create(name: "Model A", category: "Category A")
|
28
|
+
model_b = ParanoidWithScopedValidation.create(name: "Model B", category: "Category B")
|
26
29
|
|
27
30
|
ParanoidWithScopedValidation.delete([model_a.id, model_b.id])
|
28
31
|
|
@@ -31,8 +34,8 @@ class ValidatesUniquenessTest < ParanoidBaseTest
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def test_models_with_scoped_validations_can_be_multiply_destroyed
|
34
|
-
model_a = ParanoidWithScopedValidation.create(:
|
35
|
-
model_b = ParanoidWithScopedValidation.create(:
|
37
|
+
model_a = ParanoidWithScopedValidation.create(name: "Model A", category: "Category A")
|
38
|
+
model_b = ParanoidWithScopedValidation.create(name: "Model B", category: "Category B")
|
36
39
|
|
37
40
|
ParanoidWithScopedValidation.destroy([model_a.id, model_b.id])
|
38
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_paranoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Scott
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-08-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -18,54 +18,94 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '5.2'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '7.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
31
|
+
version: '5.2'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '7.0'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activesupport
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '5.2'
|
42
42
|
- - "<"
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
44
|
+
version: '7.0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
49
|
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version: '
|
51
|
+
version: '5.2'
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '7.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.5'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3.0'
|
62
65
|
type: :development
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '1.5'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4.0'
|
82
|
+
- - "<="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '6.0'
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '4.0'
|
92
|
+
- - "<="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '6.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: pry
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
69
109
|
- !ruby/object:Gem::Dependency
|
70
110
|
name: rake
|
71
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,25 +135,39 @@ dependencies:
|
|
95
135
|
- !ruby/object:Gem::Version
|
96
136
|
version: '0'
|
97
137
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
138
|
+
name: rubocop
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 0.89.1
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.89.1
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: simplecov
|
99
153
|
requirement: !ruby/object:Gem::Requirement
|
100
154
|
requirements:
|
101
155
|
- - ">="
|
102
156
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
104
|
-
- - "
|
157
|
+
version: 0.18.1
|
158
|
+
- - "<"
|
105
159
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
160
|
+
version: 0.20.0
|
107
161
|
type: :development
|
108
162
|
prerelease: false
|
109
163
|
version_requirements: !ruby/object:Gem::Requirement
|
110
164
|
requirements:
|
111
165
|
- - ">="
|
112
166
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
114
|
-
- - "
|
167
|
+
version: 0.18.1
|
168
|
+
- - "<"
|
115
169
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
170
|
+
version: 0.20.0
|
117
171
|
description: Check the home page for more in-depth information.
|
118
172
|
email:
|
119
173
|
- e@zzak.io
|
@@ -121,12 +175,12 @@ executables: []
|
|
121
175
|
extensions: []
|
122
176
|
extra_rdoc_files: []
|
123
177
|
files:
|
178
|
+
- CHANGELOG.md
|
124
179
|
- LICENSE
|
125
180
|
- README.md
|
126
181
|
- lib/acts_as_paranoid.rb
|
127
182
|
- lib/acts_as_paranoid/associations.rb
|
128
183
|
- lib/acts_as_paranoid/core.rb
|
129
|
-
- lib/acts_as_paranoid/preloader_association.rb
|
130
184
|
- lib/acts_as_paranoid/relation.rb
|
131
185
|
- lib/acts_as_paranoid/validations.rb
|
132
186
|
- lib/acts_as_paranoid/version.rb
|
@@ -135,7 +189,6 @@ files:
|
|
135
189
|
- test/test_default_scopes.rb
|
136
190
|
- test/test_helper.rb
|
137
191
|
- test/test_inheritance.rb
|
138
|
-
- test/test_preloader_association.rb
|
139
192
|
- test/test_relations.rb
|
140
193
|
- test/test_validations.rb
|
141
194
|
homepage: https://github.com/ActsAsParanoid/acts_as_paranoid
|
@@ -150,26 +203,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
203
|
requirements:
|
151
204
|
- - ">="
|
152
205
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
206
|
+
version: 2.4.0
|
154
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
208
|
requirements:
|
156
209
|
- - ">="
|
157
210
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
211
|
+
version: '0'
|
159
212
|
requirements: []
|
160
|
-
|
161
|
-
rubygems_version: 2.5.1
|
213
|
+
rubygems_version: 3.1.2
|
162
214
|
signing_key:
|
163
215
|
specification_version: 4
|
164
216
|
summary: Active Record plugin which allows you to hide and restore records without
|
165
217
|
actually deleting them.
|
166
218
|
test_files:
|
167
|
-
- test/test_inheritance.rb
|
168
|
-
- test/test_preloader_association.rb
|
169
219
|
- test/test_relations.rb
|
220
|
+
- test/test_inheritance.rb
|
170
221
|
- test/test_core.rb
|
222
|
+
- test/test_default_scopes.rb
|
223
|
+
- test/test_helper.rb
|
171
224
|
- test/test_validations.rb
|
172
225
|
- test/test_associations.rb
|
173
|
-
- test/test_helper.rb
|
174
|
-
- test/test_default_scopes.rb
|
175
|
-
has_rdoc:
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActsAsParanoid
|
2
|
-
module PreloaderAssociation
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
def build_scope_with_deleted
|
6
|
-
scope = build_scope_without_deleted
|
7
|
-
scope = scope.with_deleted if options[:with_deleted] && klass.respond_to?(:with_deleted)
|
8
|
-
scope
|
9
|
-
end
|
10
|
-
|
11
|
-
alias_method_chain :build_scope, :deleted
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PreloaderAssociationTest < ParanoidBaseTest
|
4
|
-
def test_includes_with_deleted
|
5
|
-
paranoid_time = ParanoidTime.first
|
6
|
-
paranoid_has_many_dependant = paranoid_time.paranoid_has_many_dependants.create(:name => 'dependant!')
|
7
|
-
|
8
|
-
paranoid_time.destroy
|
9
|
-
|
10
|
-
ParanoidHasManyDependant.with_deleted.includes(:paranoid_time_with_deleted).each do |hasmany|
|
11
|
-
assert_not_nil hasmany.paranoid_time_with_deleted
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_includes_with_deleted_with_polymorphic_parent
|
16
|
-
not_paranoid_parent = NotParanoidHasManyAsParent.create(name: 'not paranoid parent')
|
17
|
-
paranoid_parent = ParanoidHasManyAsParent.create(name: 'paranoid parent')
|
18
|
-
ParanoidBelongsToPolymorphic.create(:name => 'belongs_to', :parent => not_paranoid_parent)
|
19
|
-
ParanoidBelongsToPolymorphic.create(:name => 'belongs_to', :parent => paranoid_parent)
|
20
|
-
|
21
|
-
paranoid_parent.destroy
|
22
|
-
|
23
|
-
ParanoidBelongsToPolymorphic.with_deleted.includes(:parent).each do |hasmany|
|
24
|
-
assert_not_nil hasmany.parent
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|