acts_as_paranoid 0.7.2 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -0
- data/CONTRIBUTING.md +22 -11
- data/README.md +3 -3
- data/lib/acts_as_paranoid/association_reflection.rb +41 -0
- data/lib/acts_as_paranoid/associations.rb +32 -19
- data/lib/acts_as_paranoid/core.rb +74 -51
- data/lib/acts_as_paranoid/relation.rb +1 -1
- data/lib/acts_as_paranoid/version.rb +1 -1
- data/lib/acts_as_paranoid.rb +7 -7
- metadata +65 -61
- data/test/test_associations.rb +0 -358
- data/test/test_core.rb +0 -679
- data/test/test_default_scopes.rb +0 -53
- data/test/test_helper.rb +0 -565
- data/test/test_inheritance.rb +0 -16
- data/test/test_relations.rb +0 -125
- data/test/test_validations.rb +0 -45
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.8.1
|
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: 2022-04-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '5.2'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '7.
|
24
|
+
version: '7.1'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
version: '5.2'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '7.
|
34
|
+
version: '7.1'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activesupport
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
version: '5.2'
|
42
42
|
- - "<"
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '7.
|
44
|
+
version: '7.1'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,27 +51,21 @@ dependencies:
|
|
51
51
|
version: '5.2'
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '7.
|
54
|
+
version: '7.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: appraisal
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.5'
|
62
|
-
- - "<"
|
59
|
+
- - "~>"
|
63
60
|
- !ruby/object:Gem::Version
|
64
|
-
version: '3
|
61
|
+
version: '2.3'
|
65
62
|
type: :development
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
|
-
- - "
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '1.5'
|
72
|
-
- - "<"
|
66
|
+
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: '3
|
68
|
+
version: '2.3'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: minitest
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,90 +86,112 @@ dependencies:
|
|
92
86
|
requirements:
|
93
87
|
- - "~>"
|
94
88
|
- !ruby/object:Gem::Version
|
95
|
-
version: 1.
|
89
|
+
version: '1.3'
|
96
90
|
type: :development
|
97
91
|
prerelease: false
|
98
92
|
version_requirements: !ruby/object:Gem::Requirement
|
99
93
|
requirements:
|
100
94
|
- - "~>"
|
101
95
|
- !ruby/object:Gem::Version
|
102
|
-
version: 1.
|
96
|
+
version: '1.3'
|
103
97
|
- !ruby/object:Gem::Dependency
|
104
98
|
name: pry
|
105
99
|
requirement: !ruby/object:Gem::Requirement
|
106
100
|
requirements:
|
107
|
-
- - "
|
101
|
+
- - "~>"
|
108
102
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
103
|
+
version: 0.14.1
|
110
104
|
type: :development
|
111
105
|
prerelease: false
|
112
106
|
version_requirements: !ruby/object:Gem::Requirement
|
113
107
|
requirements:
|
114
|
-
- - "
|
108
|
+
- - "~>"
|
115
109
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
110
|
+
version: 0.14.1
|
117
111
|
- !ruby/object:Gem::Dependency
|
118
112
|
name: rake
|
119
113
|
requirement: !ruby/object:Gem::Requirement
|
120
114
|
requirements:
|
121
|
-
- - "
|
115
|
+
- - "~>"
|
122
116
|
- !ruby/object:Gem::Version
|
123
|
-
version: '0'
|
117
|
+
version: '13.0'
|
124
118
|
type: :development
|
125
119
|
prerelease: false
|
126
120
|
version_requirements: !ruby/object:Gem::Requirement
|
127
121
|
requirements:
|
128
|
-
- - "
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '13.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake-manifest
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.2.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
129
137
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
138
|
+
version: 0.2.0
|
131
139
|
- !ruby/object:Gem::Dependency
|
132
140
|
name: rdoc
|
133
141
|
requirement: !ruby/object:Gem::Requirement
|
134
142
|
requirements:
|
135
|
-
- - "
|
143
|
+
- - "~>"
|
136
144
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
145
|
+
version: '6.3'
|
138
146
|
type: :development
|
139
147
|
prerelease: false
|
140
148
|
version_requirements: !ruby/object:Gem::Requirement
|
141
149
|
requirements:
|
142
|
-
- - "
|
150
|
+
- - "~>"
|
143
151
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
152
|
+
version: '6.3'
|
145
153
|
- !ruby/object:Gem::Dependency
|
146
154
|
name: rubocop
|
147
155
|
requirement: !ruby/object:Gem::Requirement
|
148
156
|
requirements:
|
149
157
|
- - "~>"
|
150
158
|
- !ruby/object:Gem::Version
|
151
|
-
version: 1.
|
159
|
+
version: '1.25'
|
152
160
|
type: :development
|
153
161
|
prerelease: false
|
154
162
|
version_requirements: !ruby/object:Gem::Requirement
|
155
163
|
requirements:
|
156
164
|
- - "~>"
|
157
165
|
- !ruby/object:Gem::Version
|
158
|
-
version: 1.
|
166
|
+
version: '1.25'
|
159
167
|
- !ruby/object:Gem::Dependency
|
160
|
-
name:
|
168
|
+
name: rubocop-minitest
|
161
169
|
requirement: !ruby/object:Gem::Requirement
|
162
170
|
requirements:
|
163
|
-
- - "
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: 0.18.1
|
166
|
-
- - "<"
|
171
|
+
- - "~>"
|
167
172
|
- !ruby/object:Gem::Version
|
168
|
-
version: 0.
|
173
|
+
version: 0.19.0
|
169
174
|
type: :development
|
170
175
|
prerelease: false
|
171
176
|
version_requirements: !ruby/object:Gem::Requirement
|
172
177
|
requirements:
|
173
|
-
- - "
|
178
|
+
- - "~>"
|
174
179
|
- !ruby/object:Gem::Version
|
175
|
-
version: 0.
|
176
|
-
|
180
|
+
version: 0.19.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: simplecov
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 0.21.2
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
177
193
|
- !ruby/object:Gem::Version
|
178
|
-
version: 0.
|
194
|
+
version: 0.21.2
|
179
195
|
description: Check the home page for more in-depth information.
|
180
196
|
email:
|
181
197
|
- e@zzak.io
|
@@ -188,22 +204,17 @@ files:
|
|
188
204
|
- LICENSE
|
189
205
|
- README.md
|
190
206
|
- lib/acts_as_paranoid.rb
|
207
|
+
- lib/acts_as_paranoid/association_reflection.rb
|
191
208
|
- lib/acts_as_paranoid/associations.rb
|
192
209
|
- lib/acts_as_paranoid/core.rb
|
193
210
|
- lib/acts_as_paranoid/relation.rb
|
194
211
|
- lib/acts_as_paranoid/validations.rb
|
195
212
|
- lib/acts_as_paranoid/version.rb
|
196
|
-
- test/test_associations.rb
|
197
|
-
- test/test_core.rb
|
198
|
-
- test/test_default_scopes.rb
|
199
|
-
- test/test_helper.rb
|
200
|
-
- test/test_inheritance.rb
|
201
|
-
- test/test_relations.rb
|
202
|
-
- test/test_validations.rb
|
203
213
|
homepage: https://github.com/ActsAsParanoid/acts_as_paranoid
|
204
214
|
licenses:
|
205
215
|
- MIT
|
206
|
-
metadata:
|
216
|
+
metadata:
|
217
|
+
rubygems_mfa_required: 'true'
|
207
218
|
post_install_message:
|
208
219
|
rdoc_options: []
|
209
220
|
require_paths:
|
@@ -212,23 +223,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
212
223
|
requirements:
|
213
224
|
- - ">="
|
214
225
|
- !ruby/object:Gem::Version
|
215
|
-
version: 2.
|
226
|
+
version: 2.6.0
|
216
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
228
|
requirements:
|
218
229
|
- - ">="
|
219
230
|
- !ruby/object:Gem::Version
|
220
231
|
version: '0'
|
221
232
|
requirements: []
|
222
|
-
rubygems_version: 3.
|
233
|
+
rubygems_version: 3.3.7
|
223
234
|
signing_key:
|
224
235
|
specification_version: 4
|
225
236
|
summary: Active Record plugin which allows you to hide and restore records without
|
226
237
|
actually deleting them.
|
227
|
-
test_files:
|
228
|
-
- test/test_associations.rb
|
229
|
-
- test/test_core.rb
|
230
|
-
- test/test_default_scopes.rb
|
231
|
-
- test/test_helper.rb
|
232
|
-
- test/test_inheritance.rb
|
233
|
-
- test/test_relations.rb
|
234
|
-
- test/test_validations.rb
|
238
|
+
test_files: []
|
data/test/test_associations.rb
DELETED
@@ -1,358 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class AssociationsTest < ParanoidBaseTest
|
6
|
-
def test_removal_with_destroy_associations
|
7
|
-
paranoid_company = ParanoidDestroyCompany.create! name: "ParanoidDestroyCompany #1"
|
8
|
-
paranoid_company.paranoid_products.create! name: "ParanoidProduct #1"
|
9
|
-
|
10
|
-
assert_equal 1, ParanoidDestroyCompany.count
|
11
|
-
assert_equal 1, ParanoidProduct.count
|
12
|
-
|
13
|
-
ParanoidDestroyCompany.first.destroy
|
14
|
-
assert_equal 0, ParanoidDestroyCompany.count
|
15
|
-
assert_equal 0, ParanoidProduct.count
|
16
|
-
assert_equal 1, ParanoidDestroyCompany.with_deleted.count
|
17
|
-
assert_equal 1, ParanoidProduct.with_deleted.count
|
18
|
-
|
19
|
-
ParanoidDestroyCompany.with_deleted.first.destroy
|
20
|
-
assert_equal 0, ParanoidDestroyCompany.count
|
21
|
-
assert_equal 0, ParanoidProduct.count
|
22
|
-
assert_equal 0, ParanoidDestroyCompany.with_deleted.count
|
23
|
-
assert_equal 0, ParanoidProduct.with_deleted.count
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_removal_with_delete_all_associations
|
27
|
-
paranoid_company = ParanoidDeleteCompany.create! name: "ParanoidDestroyCompany #1"
|
28
|
-
paranoid_company.paranoid_products.create! name: "ParanoidProduct #2"
|
29
|
-
|
30
|
-
assert_equal 1, ParanoidDeleteCompany.count
|
31
|
-
assert_equal 1, ParanoidProduct.count
|
32
|
-
|
33
|
-
ParanoidDeleteCompany.first.destroy
|
34
|
-
assert_equal 0, ParanoidDeleteCompany.count
|
35
|
-
assert_equal 0, ParanoidProduct.count
|
36
|
-
assert_equal 1, ParanoidDeleteCompany.with_deleted.count
|
37
|
-
assert_equal 1, ParanoidProduct.with_deleted.count
|
38
|
-
|
39
|
-
ParanoidDeleteCompany.with_deleted.first.destroy
|
40
|
-
assert_equal 0, ParanoidDeleteCompany.count
|
41
|
-
assert_equal 0, ParanoidProduct.count
|
42
|
-
assert_equal 0, ParanoidDeleteCompany.with_deleted.count
|
43
|
-
assert_equal 0, ParanoidProduct.with_deleted.count
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_belongs_to_with_scope_option
|
47
|
-
paranoid_has_many_dependant = ParanoidHasManyDependant.new
|
48
|
-
|
49
|
-
expected_includes_values = ParanoidTime.includes(:not_paranoid).includes_values
|
50
|
-
includes_values = paranoid_has_many_dependant
|
51
|
-
.association(:paranoid_time_with_scope).scope.includes_values
|
52
|
-
|
53
|
-
assert_equal expected_includes_values, includes_values
|
54
|
-
|
55
|
-
paranoid_time = ParanoidTime.create(name: "not-hello")
|
56
|
-
paranoid_has_many_dependant.paranoid_time = paranoid_time
|
57
|
-
paranoid_has_many_dependant.save!
|
58
|
-
|
59
|
-
assert_nil paranoid_has_many_dependant.paranoid_time_with_scope
|
60
|
-
|
61
|
-
paranoid_time.update(name: "hello")
|
62
|
-
|
63
|
-
paranoid_has_many_dependant.reload
|
64
|
-
|
65
|
-
assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time_with_scope
|
66
|
-
|
67
|
-
paranoid_time.destroy
|
68
|
-
|
69
|
-
paranoid_has_many_dependant.reload
|
70
|
-
|
71
|
-
assert_nil paranoid_has_many_dependant.paranoid_time_with_scope
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_belongs_to_with_scope_and_deleted_option
|
75
|
-
paranoid_has_many_dependant = ParanoidHasManyDependant.new
|
76
|
-
includes_values = ParanoidTime.includes(:not_paranoid).includes_values
|
77
|
-
|
78
|
-
assert_equal includes_values, paranoid_has_many_dependant
|
79
|
-
.association(:paranoid_time_with_scope_with_deleted).scope.includes_values
|
80
|
-
|
81
|
-
paranoid_time = ParanoidTime.create(name: "not-hello")
|
82
|
-
paranoid_has_many_dependant.paranoid_time = paranoid_time
|
83
|
-
paranoid_has_many_dependant.save!
|
84
|
-
|
85
|
-
assert_nil paranoid_has_many_dependant.paranoid_time_with_scope_with_deleted
|
86
|
-
|
87
|
-
paranoid_time.update(name: "hello")
|
88
|
-
paranoid_has_many_dependant.reload
|
89
|
-
|
90
|
-
assert_equal paranoid_time, paranoid_has_many_dependant
|
91
|
-
.paranoid_time_with_scope_with_deleted
|
92
|
-
|
93
|
-
paranoid_time.destroy
|
94
|
-
paranoid_has_many_dependant.reload
|
95
|
-
|
96
|
-
assert_equal paranoid_time, paranoid_has_many_dependant
|
97
|
-
.paranoid_time_with_scope_with_deleted
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_belongs_to_with_deleted
|
101
|
-
paranoid_time = ParanoidTime.first
|
102
|
-
paranoid_has_many_dependant = paranoid_time.paranoid_has_many_dependants
|
103
|
-
.create(name: "dependant!")
|
104
|
-
|
105
|
-
assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time
|
106
|
-
assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time_with_deleted
|
107
|
-
|
108
|
-
paranoid_time.destroy
|
109
|
-
paranoid_has_many_dependant.reload
|
110
|
-
|
111
|
-
assert_nil paranoid_has_many_dependant.paranoid_time
|
112
|
-
assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time_with_deleted
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_belongs_to_polymorphic_with_deleted
|
116
|
-
paranoid_time = ParanoidTime.first
|
117
|
-
paranoid_has_many_dependant = ParanoidHasManyDependant
|
118
|
-
.create!(name: "dependant!", paranoid_time_polymorphic_with_deleted: paranoid_time)
|
119
|
-
|
120
|
-
assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time
|
121
|
-
assert_equal paranoid_time, paranoid_has_many_dependant
|
122
|
-
.paranoid_time_polymorphic_with_deleted
|
123
|
-
|
124
|
-
paranoid_time.destroy
|
125
|
-
|
126
|
-
assert_nil paranoid_has_many_dependant.reload.paranoid_time
|
127
|
-
assert_equal paranoid_time, paranoid_has_many_dependant
|
128
|
-
.reload.paranoid_time_polymorphic_with_deleted
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_belongs_to_nil_polymorphic_with_deleted
|
132
|
-
paranoid_time = ParanoidTime.first
|
133
|
-
paranoid_has_many_dependant =
|
134
|
-
ParanoidHasManyDependant.create!(name: "dependant!",
|
135
|
-
paranoid_time_polymorphic_with_deleted: nil)
|
136
|
-
|
137
|
-
assert_nil paranoid_has_many_dependant.paranoid_time
|
138
|
-
assert_nil paranoid_has_many_dependant.paranoid_time_polymorphic_with_deleted
|
139
|
-
|
140
|
-
paranoid_time.destroy
|
141
|
-
|
142
|
-
assert_nil paranoid_has_many_dependant.reload.paranoid_time
|
143
|
-
assert_nil paranoid_has_many_dependant.reload.paranoid_time_polymorphic_with_deleted
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_belongs_to_options
|
147
|
-
paranoid_time = ParanoidHasManyDependant.reflections
|
148
|
-
.with_indifferent_access[:paranoid_time]
|
149
|
-
assert_equal :belongs_to, paranoid_time.macro
|
150
|
-
assert_nil paranoid_time.options[:with_deleted]
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_belongs_to_with_deleted_options
|
154
|
-
paranoid_time_with_deleted =
|
155
|
-
ParanoidHasManyDependant.reflections
|
156
|
-
.with_indifferent_access[:paranoid_time_with_deleted]
|
157
|
-
assert_equal :belongs_to, paranoid_time_with_deleted.macro
|
158
|
-
assert paranoid_time_with_deleted.options[:with_deleted]
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_belongs_to_polymorphic_with_deleted_options
|
162
|
-
paranoid_time_polymorphic_with_deleted = ParanoidHasManyDependant.reflections
|
163
|
-
.with_indifferent_access[:paranoid_time_polymorphic_with_deleted]
|
164
|
-
assert_equal :belongs_to, paranoid_time_polymorphic_with_deleted.macro
|
165
|
-
assert paranoid_time_polymorphic_with_deleted.options[:with_deleted]
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_only_find_associated_records_when_finding_with_paranoid_deleted
|
169
|
-
parent = ParanoidBelongsDependant.create
|
170
|
-
child = ParanoidHasManyDependant.create
|
171
|
-
parent.paranoid_has_many_dependants << child
|
172
|
-
|
173
|
-
unrelated_parent = ParanoidBelongsDependant.create
|
174
|
-
unrelated_child = ParanoidHasManyDependant.create
|
175
|
-
unrelated_parent.paranoid_has_many_dependants << unrelated_child
|
176
|
-
|
177
|
-
child.destroy
|
178
|
-
assert_paranoid_deletion(child)
|
179
|
-
|
180
|
-
parent.reload
|
181
|
-
|
182
|
-
assert_equal [], parent.paranoid_has_many_dependants.to_a
|
183
|
-
assert_equal [child], parent.paranoid_has_many_dependants.with_deleted.to_a
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_join_with_model_with_deleted
|
187
|
-
obj = ParanoidHasManyDependant.create(paranoid_time: ParanoidTime.create)
|
188
|
-
assert_not_nil obj.paranoid_time
|
189
|
-
assert_not_nil obj.paranoid_time_with_deleted
|
190
|
-
|
191
|
-
obj.paranoid_time.destroy
|
192
|
-
obj.reload
|
193
|
-
|
194
|
-
assert_nil obj.paranoid_time
|
195
|
-
assert_not_nil obj.paranoid_time_with_deleted
|
196
|
-
|
197
|
-
# Note that obj is destroyed because of dependent: :destroy in ParanoidTime
|
198
|
-
assert obj.destroyed?
|
199
|
-
|
200
|
-
assert_empty ParanoidHasManyDependant.with_deleted.joins(:paranoid_time)
|
201
|
-
assert_equal [obj],
|
202
|
-
ParanoidHasManyDependant.with_deleted.joins(:paranoid_time_with_deleted)
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_includes_with_deleted
|
206
|
-
paranoid_time = ParanoidTime.first
|
207
|
-
paranoid_time.paranoid_has_many_dependants.create(name: "dependant!")
|
208
|
-
|
209
|
-
paranoid_time.destroy
|
210
|
-
|
211
|
-
ParanoidHasManyDependant.with_deleted
|
212
|
-
.includes(:paranoid_time_with_deleted).each do |hasmany|
|
213
|
-
assert_not_nil hasmany.paranoid_time_with_deleted
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_includes_with_deleted_with_polymorphic_parent
|
218
|
-
not_paranoid_parent = NotParanoidHasManyAsParent.create(name: "not paranoid parent")
|
219
|
-
paranoid_parent = ParanoidHasManyAsParent.create(name: "paranoid parent")
|
220
|
-
ParanoidBelongsToPolymorphic.create(name: "belongs_to", parent: not_paranoid_parent)
|
221
|
-
ParanoidBelongsToPolymorphic.create(name: "belongs_to", parent: paranoid_parent)
|
222
|
-
|
223
|
-
paranoid_parent.destroy
|
224
|
-
|
225
|
-
ParanoidBelongsToPolymorphic.with_deleted.includes(:parent).each do |hasmany|
|
226
|
-
assert_not_nil hasmany.parent
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_cannot_find_a_paranoid_deleted_many_many_association
|
231
|
-
left = ParanoidManyManyParentLeft.create
|
232
|
-
right = ParanoidManyManyParentRight.create
|
233
|
-
left.paranoid_many_many_parent_rights << right
|
234
|
-
|
235
|
-
left.paranoid_many_many_parent_rights.delete(right)
|
236
|
-
|
237
|
-
left.reload
|
238
|
-
|
239
|
-
assert_equal [], left.paranoid_many_many_children, "Linking objects not deleted"
|
240
|
-
assert_equal [], left.paranoid_many_many_parent_rights,
|
241
|
-
"Associated objects not unlinked"
|
242
|
-
assert_equal right, ParanoidManyManyParentRight.find(right.id),
|
243
|
-
"Associated object deleted"
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_cannot_find_a_paranoid_destroyed_many_many_association
|
247
|
-
left = ParanoidManyManyParentLeft.create
|
248
|
-
right = ParanoidManyManyParentRight.create
|
249
|
-
left.paranoid_many_many_parent_rights << right
|
250
|
-
|
251
|
-
left.paranoid_many_many_parent_rights.destroy(right)
|
252
|
-
|
253
|
-
left.reload
|
254
|
-
|
255
|
-
assert_equal [], left.paranoid_many_many_children, "Linking objects not deleted"
|
256
|
-
assert_equal [], left.paranoid_many_many_parent_rights,
|
257
|
-
"Associated objects not unlinked"
|
258
|
-
assert_equal right, ParanoidManyManyParentRight.find(right.id),
|
259
|
-
"Associated object deleted"
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_cannot_find_a_has_many_through_object_when_its_linking_object_is_soft_destroyed
|
263
|
-
left = ParanoidManyManyParentLeft.create
|
264
|
-
right = ParanoidManyManyParentRight.create
|
265
|
-
left.paranoid_many_many_parent_rights << right
|
266
|
-
|
267
|
-
child = left.paranoid_many_many_children.first
|
268
|
-
|
269
|
-
child.destroy
|
270
|
-
|
271
|
-
left.reload
|
272
|
-
|
273
|
-
assert_equal [], left.paranoid_many_many_parent_rights, "Associated objects not deleted"
|
274
|
-
end
|
275
|
-
|
276
|
-
def test_cannot_find_a_paranoid_deleted_model
|
277
|
-
model = ParanoidBelongsDependant.create
|
278
|
-
model.destroy
|
279
|
-
|
280
|
-
assert_raises ActiveRecord::RecordNotFound do
|
281
|
-
ParanoidBelongsDependant.find(model.id)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_bidirectional_has_many_through_association_clear_is_paranoid
|
286
|
-
left = ParanoidManyManyParentLeft.create
|
287
|
-
right = ParanoidManyManyParentRight.create
|
288
|
-
left.paranoid_many_many_parent_rights << right
|
289
|
-
|
290
|
-
child = left.paranoid_many_many_children.first
|
291
|
-
assert_equal left, child.paranoid_many_many_parent_left,
|
292
|
-
"Child's left parent is incorrect"
|
293
|
-
assert_equal right, child.paranoid_many_many_parent_right,
|
294
|
-
"Child's right parent is incorrect"
|
295
|
-
|
296
|
-
left.paranoid_many_many_parent_rights.clear
|
297
|
-
|
298
|
-
assert_paranoid_deletion(child)
|
299
|
-
end
|
300
|
-
|
301
|
-
def test_bidirectional_has_many_through_association_destroy_is_paranoid
|
302
|
-
left = ParanoidManyManyParentLeft.create
|
303
|
-
right = ParanoidManyManyParentRight.create
|
304
|
-
left.paranoid_many_many_parent_rights << right
|
305
|
-
|
306
|
-
child = left.paranoid_many_many_children.first
|
307
|
-
assert_equal left, child.paranoid_many_many_parent_left,
|
308
|
-
"Child's left parent is incorrect"
|
309
|
-
assert_equal right, child.paranoid_many_many_parent_right,
|
310
|
-
"Child's right parent is incorrect"
|
311
|
-
|
312
|
-
left.paranoid_many_many_parent_rights.destroy(right)
|
313
|
-
|
314
|
-
assert_paranoid_deletion(child)
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_bidirectional_has_many_through_association_delete_is_paranoid
|
318
|
-
left = ParanoidManyManyParentLeft.create
|
319
|
-
right = ParanoidManyManyParentRight.create
|
320
|
-
left.paranoid_many_many_parent_rights << right
|
321
|
-
|
322
|
-
child = left.paranoid_many_many_children.first
|
323
|
-
assert_equal left, child.paranoid_many_many_parent_left,
|
324
|
-
"Child's left parent is incorrect"
|
325
|
-
assert_equal right, child.paranoid_many_many_parent_right,
|
326
|
-
"Child's right parent is incorrect"
|
327
|
-
|
328
|
-
left.paranoid_many_many_parent_rights.delete(right)
|
329
|
-
|
330
|
-
assert_paranoid_deletion(child)
|
331
|
-
end
|
332
|
-
|
333
|
-
def test_belongs_to_on_normal_model_is_paranoid
|
334
|
-
not_paranoid = HasOneNotParanoid.create
|
335
|
-
not_paranoid.paranoid_time = ParanoidTime.create
|
336
|
-
|
337
|
-
assert not_paranoid.save
|
338
|
-
assert_not_nil not_paranoid.paranoid_time
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_double_belongs_to_with_deleted
|
342
|
-
not_paranoid = DoubleHasOneNotParanoid.create
|
343
|
-
not_paranoid.paranoid_time = ParanoidTime.create
|
344
|
-
|
345
|
-
assert not_paranoid.save
|
346
|
-
assert_not_nil not_paranoid.paranoid_time
|
347
|
-
end
|
348
|
-
|
349
|
-
def test_mass_assignment_of_paranoid_column_enabled
|
350
|
-
if Gem.loaded_specs["activerecord"].version >= Gem::Version.new("5.2.0")
|
351
|
-
skip "Creation as deleted is not supported with Rails >= 5.2"
|
352
|
-
end
|
353
|
-
now = Time.now
|
354
|
-
record = ParanoidTime.create! name: "Foo", deleted_at: now
|
355
|
-
assert_equal "Foo", record.name
|
356
|
-
assert_equal now, record.deleted_at
|
357
|
-
end
|
358
|
-
end
|