acts_as_paranoid 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +70 -0
- data/CONTRIBUTING.md +58 -0
- data/README.md +5 -5
- data/lib/acts_as_paranoid/core.rb +80 -55
- data/lib/acts_as_paranoid/relation.rb +1 -1
- data/lib/acts_as_paranoid/version.rb +1 -1
- data/lib/acts_as_paranoid.rb +4 -4
- metadata +71 -73
- data/test/test_associations.rb +0 -358
- data/test/test_core.rb +0 -633
- data/test/test_default_scopes.rb +0 -53
- data/test/test_helper.rb +0 -541
- data/test/test_inheritance.rb +0 -16
- data/test/test_relations.rb +0 -125
- data/test/test_validations.rb +0 -45
data/test/test_core.rb
DELETED
@@ -1,633 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class ParanoidTest < ParanoidBaseTest
|
6
|
-
def test_paranoid?
|
7
|
-
assert !NotParanoid.paranoid?
|
8
|
-
assert_raise(NoMethodError) { NotParanoid.delete_all! }
|
9
|
-
assert_raise(NoMethodError) { NotParanoid.with_deleted }
|
10
|
-
assert_raise(NoMethodError) { NotParanoid.only_deleted }
|
11
|
-
|
12
|
-
assert ParanoidTime.paranoid?
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_scope_inclusion_with_time_column_type
|
16
|
-
assert ParanoidTime.respond_to?(:deleted_inside_time_window)
|
17
|
-
assert ParanoidTime.respond_to?(:deleted_before_time)
|
18
|
-
assert ParanoidTime.respond_to?(:deleted_after_time)
|
19
|
-
|
20
|
-
assert !ParanoidBoolean.respond_to?(:deleted_inside_time_window)
|
21
|
-
assert !ParanoidBoolean.respond_to?(:deleted_before_time)
|
22
|
-
assert !ParanoidBoolean.respond_to?(:deleted_after_time)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_fake_removal
|
26
|
-
assert_equal 3, ParanoidTime.count
|
27
|
-
assert_equal 3, ParanoidBoolean.count
|
28
|
-
assert_equal 1, ParanoidString.count
|
29
|
-
|
30
|
-
ParanoidTime.first.destroy
|
31
|
-
ParanoidBoolean.delete_all("name = 'paranoid' OR name = 'really paranoid'")
|
32
|
-
ParanoidString.first.destroy
|
33
|
-
assert_equal 2, ParanoidTime.count
|
34
|
-
assert_equal 1, ParanoidBoolean.count
|
35
|
-
assert_equal 0, ParanoidString.count
|
36
|
-
assert_equal 1, ParanoidTime.only_deleted.count
|
37
|
-
assert_equal 2, ParanoidBoolean.only_deleted.count
|
38
|
-
assert_equal 1, ParanoidString.only_deleted.count
|
39
|
-
assert_equal 3, ParanoidTime.with_deleted.count
|
40
|
-
assert_equal 3, ParanoidBoolean.with_deleted.count
|
41
|
-
assert_equal 1, ParanoidString.with_deleted.count
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_real_removal
|
45
|
-
ParanoidTime.first.destroy_fully!
|
46
|
-
ParanoidBoolean.delete_all!("name = 'extremely paranoid' OR name = 'really paranoid'")
|
47
|
-
ParanoidString.first.destroy_fully!
|
48
|
-
assert_equal 2, ParanoidTime.count
|
49
|
-
assert_equal 1, ParanoidBoolean.count
|
50
|
-
assert_equal 0, ParanoidString.count
|
51
|
-
assert_equal 2, ParanoidTime.with_deleted.count
|
52
|
-
assert_equal 1, ParanoidBoolean.with_deleted.count
|
53
|
-
assert_equal 0, ParanoidString.with_deleted.count
|
54
|
-
assert_equal 0, ParanoidTime.only_deleted.count
|
55
|
-
assert_equal 0, ParanoidBoolean.only_deleted.count
|
56
|
-
assert_equal 0, ParanoidString.only_deleted.count
|
57
|
-
|
58
|
-
ParanoidTime.first.destroy
|
59
|
-
ParanoidTime.only_deleted.first.destroy
|
60
|
-
assert_equal 0, ParanoidTime.only_deleted.count
|
61
|
-
|
62
|
-
ParanoidTime.delete_all!
|
63
|
-
assert_empty ParanoidTime.all
|
64
|
-
assert_empty ParanoidTime.with_deleted
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_non_persisted_destroy
|
68
|
-
pt = ParanoidTime.new
|
69
|
-
assert_nil pt.paranoid_value
|
70
|
-
pt.destroy
|
71
|
-
assert_not_nil pt.paranoid_value
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_non_persisted_delete
|
75
|
-
pt = ParanoidTime.new
|
76
|
-
assert_nil pt.paranoid_value
|
77
|
-
pt.delete
|
78
|
-
assert_not_nil pt.paranoid_value
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_non_persisted_destroy!
|
82
|
-
pt = ParanoidTime.new
|
83
|
-
assert_nil pt.paranoid_value
|
84
|
-
pt.destroy!
|
85
|
-
assert_not_nil pt.paranoid_value
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_removal_not_persisted
|
89
|
-
assert ParanoidTime.new.destroy
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_recovery
|
93
|
-
assert_equal 3, ParanoidBoolean.count
|
94
|
-
ParanoidBoolean.first.destroy
|
95
|
-
assert_equal 2, ParanoidBoolean.count
|
96
|
-
ParanoidBoolean.only_deleted.first.recover
|
97
|
-
assert_equal 3, ParanoidBoolean.count
|
98
|
-
|
99
|
-
assert_equal 1, ParanoidString.count
|
100
|
-
ParanoidString.first.destroy
|
101
|
-
assert_equal 0, ParanoidString.count
|
102
|
-
ParanoidString.with_deleted.first.recover
|
103
|
-
assert_equal 1, ParanoidString.count
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_recovery!
|
107
|
-
ParanoidBoolean.first.destroy
|
108
|
-
ParanoidBoolean.create(name: "paranoid")
|
109
|
-
|
110
|
-
assert_raise do
|
111
|
-
ParanoidBoolean.only_deleted.first.recover!
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Rails does not allow saving deleted records
|
116
|
-
def test_no_save_after_destroy
|
117
|
-
paranoid = ParanoidString.first
|
118
|
-
paranoid.destroy
|
119
|
-
paranoid.name = "Let's update!"
|
120
|
-
|
121
|
-
assert_not paranoid.save
|
122
|
-
assert_raises ActiveRecord::RecordNotSaved do
|
123
|
-
paranoid.save!
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def setup_recursive_tests
|
128
|
-
@paranoid_time_object = ParanoidTime.first
|
129
|
-
|
130
|
-
# Create one extra ParanoidHasManyDependant record so that we can validate
|
131
|
-
# the correct dependants are recovered.
|
132
|
-
ParanoidTime.where("id <> ?", @paranoid_time_object.id).first
|
133
|
-
.paranoid_has_many_dependants.create(name: "should not be recovered").destroy
|
134
|
-
|
135
|
-
@paranoid_boolean_count = ParanoidBoolean.count
|
136
|
-
|
137
|
-
assert_equal 0, ParanoidHasManyDependant.count
|
138
|
-
assert_equal 0, ParanoidBelongsDependant.count
|
139
|
-
assert_equal 1, NotParanoid.count
|
140
|
-
|
141
|
-
(1..3).each do |i|
|
142
|
-
has_many_object = @paranoid_time_object.paranoid_has_many_dependants
|
143
|
-
.create(name: "has_many_#{i}")
|
144
|
-
has_many_object.create_paranoid_belongs_dependant(name: "belongs_to_#{i}")
|
145
|
-
has_many_object.save
|
146
|
-
|
147
|
-
paranoid_boolean = @paranoid_time_object.paranoid_booleans
|
148
|
-
.create(name: "boolean_#{i}")
|
149
|
-
paranoid_boolean.create_paranoid_has_one_dependant(name: "has_one_#{i}")
|
150
|
-
paranoid_boolean.save
|
151
|
-
|
152
|
-
@paranoid_time_object.not_paranoids.create(name: "not_paranoid_a#{i}")
|
153
|
-
end
|
154
|
-
|
155
|
-
@paranoid_time_object.create_not_paranoid(name: "not_paranoid_belongs_to")
|
156
|
-
@paranoid_time_object.create_has_one_not_paranoid(name: "has_one_not_paranoid")
|
157
|
-
|
158
|
-
assert_equal 3, ParanoidTime.count
|
159
|
-
assert_equal 3, ParanoidHasManyDependant.count
|
160
|
-
assert_equal 3, ParanoidBelongsDependant.count
|
161
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
|
162
|
-
assert_equal 3, ParanoidHasOneDependant.count
|
163
|
-
assert_equal 5, NotParanoid.count
|
164
|
-
assert_equal 1, HasOneNotParanoid.count
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_recursive_fake_removal
|
168
|
-
setup_recursive_tests
|
169
|
-
|
170
|
-
@paranoid_time_object.destroy
|
171
|
-
|
172
|
-
assert_equal 2, ParanoidTime.count
|
173
|
-
assert_equal 0, ParanoidHasManyDependant.count
|
174
|
-
assert_equal 0, ParanoidBelongsDependant.count
|
175
|
-
assert_equal @paranoid_boolean_count, ParanoidBoolean.count
|
176
|
-
assert_equal 0, ParanoidHasOneDependant.count
|
177
|
-
assert_equal 1, NotParanoid.count
|
178
|
-
assert_equal 0, HasOneNotParanoid.count
|
179
|
-
|
180
|
-
assert_equal 3, ParanoidTime.with_deleted.count
|
181
|
-
assert_equal 4, ParanoidHasManyDependant.with_deleted.count
|
182
|
-
assert_equal 3, ParanoidBelongsDependant.with_deleted.count
|
183
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.with_deleted.count
|
184
|
-
assert_equal 3, ParanoidHasOneDependant.with_deleted.count
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_recursive_real_removal
|
188
|
-
setup_recursive_tests
|
189
|
-
|
190
|
-
@paranoid_time_object.destroy_fully!
|
191
|
-
|
192
|
-
assert_equal 0, ParanoidTime.only_deleted.count
|
193
|
-
assert_equal 1, ParanoidHasManyDependant.only_deleted.count
|
194
|
-
assert_equal 0, ParanoidBelongsDependant.only_deleted.count
|
195
|
-
assert_equal 0, ParanoidBoolean.only_deleted.count
|
196
|
-
assert_equal 0, ParanoidHasOneDependant.only_deleted.count
|
197
|
-
assert_equal 1, NotParanoid.count
|
198
|
-
assert_equal 0, HasOneNotParanoid.count
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_recursive_recovery
|
202
|
-
setup_recursive_tests
|
203
|
-
|
204
|
-
@paranoid_time_object.destroy
|
205
|
-
@paranoid_time_object.reload
|
206
|
-
|
207
|
-
@paranoid_time_object.recover(recursive: true)
|
208
|
-
|
209
|
-
assert_equal 3, ParanoidTime.count
|
210
|
-
assert_equal 3, ParanoidHasManyDependant.count
|
211
|
-
assert_equal 3, ParanoidBelongsDependant.count
|
212
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
|
213
|
-
assert_equal 3, ParanoidHasOneDependant.count
|
214
|
-
assert_equal 1, NotParanoid.count
|
215
|
-
assert_equal 0, HasOneNotParanoid.count
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_recursive_recovery_dependant_window
|
219
|
-
setup_recursive_tests
|
220
|
-
|
221
|
-
# Stop the following from recovering:
|
222
|
-
# - ParanoidHasManyDependant and its ParanoidBelongsDependant
|
223
|
-
# - A single ParanoidBelongsDependant, but not its parent
|
224
|
-
Time.stub :now, 2.days.ago do
|
225
|
-
@paranoid_time_object.paranoid_has_many_dependants.first.destroy
|
226
|
-
end
|
227
|
-
Time.stub :now, 1.hour.ago do
|
228
|
-
@paranoid_time_object.paranoid_has_many_dependants
|
229
|
-
.last.paranoid_belongs_dependant
|
230
|
-
.destroy
|
231
|
-
end
|
232
|
-
@paranoid_time_object.destroy
|
233
|
-
@paranoid_time_object.reload
|
234
|
-
|
235
|
-
@paranoid_time_object.recover(recursive: true)
|
236
|
-
|
237
|
-
assert_equal 3, ParanoidTime.count
|
238
|
-
assert_equal 2, ParanoidHasManyDependant.count
|
239
|
-
assert_equal 1, ParanoidBelongsDependant.count
|
240
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
|
241
|
-
assert_equal 3, ParanoidHasOneDependant.count
|
242
|
-
assert_equal 1, NotParanoid.count
|
243
|
-
assert_equal 0, HasOneNotParanoid.count
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_recursive_recovery_for_belongs_to_polymorphic
|
247
|
-
child_1 = ParanoidAndroid.create
|
248
|
-
section_1 = ParanoidSection.create(paranoid_thing: child_1)
|
249
|
-
|
250
|
-
child_2 = ParanoidPolygon.create(sides: 3)
|
251
|
-
section_2 = ParanoidSection.create(paranoid_thing: child_2)
|
252
|
-
|
253
|
-
assert_equal section_1.paranoid_thing, child_1
|
254
|
-
assert_equal section_1.paranoid_thing.class, ParanoidAndroid
|
255
|
-
assert_equal section_2.paranoid_thing, child_2
|
256
|
-
assert_equal section_2.paranoid_thing.class, ParanoidPolygon
|
257
|
-
|
258
|
-
parent = ParanoidTime.create(name: "paranoid_parent")
|
259
|
-
parent.paranoid_sections << section_1
|
260
|
-
parent.paranoid_sections << section_2
|
261
|
-
|
262
|
-
assert_equal 4, ParanoidTime.count
|
263
|
-
assert_equal 2, ParanoidSection.count
|
264
|
-
assert_equal 1, ParanoidAndroid.count
|
265
|
-
assert_equal 1, ParanoidPolygon.count
|
266
|
-
|
267
|
-
parent.destroy
|
268
|
-
|
269
|
-
assert_equal 3, ParanoidTime.count
|
270
|
-
assert_equal 0, ParanoidSection.count
|
271
|
-
assert_equal 0, ParanoidAndroid.count
|
272
|
-
assert_equal 0, ParanoidPolygon.count
|
273
|
-
|
274
|
-
parent.reload
|
275
|
-
parent.recover
|
276
|
-
|
277
|
-
assert_equal 4, ParanoidTime.count
|
278
|
-
assert_equal 2, ParanoidSection.count
|
279
|
-
assert_equal 1, ParanoidAndroid.count
|
280
|
-
assert_equal 1, ParanoidPolygon.count
|
281
|
-
end
|
282
|
-
|
283
|
-
def test_non_recursive_recovery
|
284
|
-
setup_recursive_tests
|
285
|
-
|
286
|
-
@paranoid_time_object.destroy
|
287
|
-
@paranoid_time_object.reload
|
288
|
-
|
289
|
-
@paranoid_time_object.recover(recursive: false)
|
290
|
-
|
291
|
-
assert_equal 3, ParanoidTime.count
|
292
|
-
assert_equal 0, ParanoidHasManyDependant.count
|
293
|
-
assert_equal 0, ParanoidBelongsDependant.count
|
294
|
-
assert_equal @paranoid_boolean_count, ParanoidBoolean.count
|
295
|
-
assert_equal 0, ParanoidHasOneDependant.count
|
296
|
-
assert_equal 1, NotParanoid.count
|
297
|
-
assert_equal 0, HasOneNotParanoid.count
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_dirty
|
301
|
-
pt = ParanoidTime.create
|
302
|
-
pt.destroy
|
303
|
-
assert_not pt.changed?
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_delete_dirty
|
307
|
-
pt = ParanoidTime.create
|
308
|
-
pt.delete
|
309
|
-
assert_not pt.changed?
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_destroy_fully_dirty
|
313
|
-
pt = ParanoidTime.create
|
314
|
-
pt.destroy_fully!
|
315
|
-
assert_not pt.changed?
|
316
|
-
end
|
317
|
-
|
318
|
-
def test_deleted?
|
319
|
-
ParanoidTime.first.destroy
|
320
|
-
assert ParanoidTime.with_deleted.first.deleted?
|
321
|
-
|
322
|
-
ParanoidString.first.destroy
|
323
|
-
assert ParanoidString.with_deleted.first.deleted?
|
324
|
-
end
|
325
|
-
|
326
|
-
def test_delete_deleted?
|
327
|
-
ParanoidTime.first.delete
|
328
|
-
assert ParanoidTime.with_deleted.first.deleted?
|
329
|
-
|
330
|
-
ParanoidString.first.delete
|
331
|
-
assert ParanoidString.with_deleted.first.deleted?
|
332
|
-
end
|
333
|
-
|
334
|
-
def test_destroy_fully_deleted?
|
335
|
-
object = ParanoidTime.first
|
336
|
-
object.destroy_fully!
|
337
|
-
assert object.deleted?
|
338
|
-
|
339
|
-
object = ParanoidString.first
|
340
|
-
object.destroy_fully!
|
341
|
-
assert object.deleted?
|
342
|
-
end
|
343
|
-
|
344
|
-
def test_deleted_fully?
|
345
|
-
ParanoidTime.first.destroy
|
346
|
-
assert_not ParanoidTime.with_deleted.first.deleted_fully?
|
347
|
-
|
348
|
-
ParanoidString.first.destroy
|
349
|
-
assert ParanoidString.with_deleted.first.deleted?
|
350
|
-
end
|
351
|
-
|
352
|
-
def test_delete_deleted_fully?
|
353
|
-
ParanoidTime.first.delete
|
354
|
-
assert_not ParanoidTime.with_deleted.first.deleted_fully?
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_destroy_fully_deleted_fully?
|
358
|
-
object = ParanoidTime.first
|
359
|
-
object.destroy_fully!
|
360
|
-
assert object.deleted_fully?
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_paranoid_destroy_callbacks
|
364
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
365
|
-
ParanoidWithCallback.transaction do
|
366
|
-
@paranoid_with_callback.destroy
|
367
|
-
end
|
368
|
-
|
369
|
-
assert @paranoid_with_callback.called_before_destroy
|
370
|
-
assert @paranoid_with_callback.called_after_destroy
|
371
|
-
assert @paranoid_with_callback.called_after_commit_on_destroy
|
372
|
-
end
|
373
|
-
|
374
|
-
def test_hard_destroy_callbacks
|
375
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
376
|
-
|
377
|
-
ParanoidWithCallback.transaction do
|
378
|
-
@paranoid_with_callback.destroy!
|
379
|
-
end
|
380
|
-
|
381
|
-
assert @paranoid_with_callback.called_before_destroy
|
382
|
-
assert @paranoid_with_callback.called_after_destroy
|
383
|
-
assert @paranoid_with_callback.called_after_commit_on_destroy
|
384
|
-
end
|
385
|
-
|
386
|
-
def test_recovery_callbacks
|
387
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
388
|
-
|
389
|
-
ParanoidWithCallback.transaction do
|
390
|
-
@paranoid_with_callback.destroy
|
391
|
-
|
392
|
-
assert_nil @paranoid_with_callback.called_before_recover
|
393
|
-
assert_nil @paranoid_with_callback.called_after_recover
|
394
|
-
|
395
|
-
@paranoid_with_callback.recover
|
396
|
-
end
|
397
|
-
|
398
|
-
assert @paranoid_with_callback.called_before_recover
|
399
|
-
assert @paranoid_with_callback.called_after_recover
|
400
|
-
end
|
401
|
-
|
402
|
-
def test_recovery_callbacks_without_destroy
|
403
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
404
|
-
@paranoid_with_callback.recover
|
405
|
-
|
406
|
-
assert_nil @paranoid_with_callback.called_before_recover
|
407
|
-
assert_nil @paranoid_with_callback.called_after_recover
|
408
|
-
end
|
409
|
-
|
410
|
-
def test_delete_by_multiple_id_is_paranoid
|
411
|
-
model_a = ParanoidBelongsDependant.create
|
412
|
-
model_b = ParanoidBelongsDependant.create
|
413
|
-
ParanoidBelongsDependant.delete([model_a.id, model_b.id])
|
414
|
-
|
415
|
-
assert_paranoid_deletion(model_a)
|
416
|
-
assert_paranoid_deletion(model_b)
|
417
|
-
end
|
418
|
-
|
419
|
-
def test_destroy_by_multiple_id_is_paranoid
|
420
|
-
model_a = ParanoidBelongsDependant.create
|
421
|
-
model_b = ParanoidBelongsDependant.create
|
422
|
-
ParanoidBelongsDependant.destroy([model_a.id, model_b.id])
|
423
|
-
|
424
|
-
assert_paranoid_deletion(model_a)
|
425
|
-
assert_paranoid_deletion(model_b)
|
426
|
-
end
|
427
|
-
|
428
|
-
def test_delete_by_single_id_is_paranoid
|
429
|
-
model = ParanoidBelongsDependant.create
|
430
|
-
ParanoidBelongsDependant.delete(model.id)
|
431
|
-
|
432
|
-
assert_paranoid_deletion(model)
|
433
|
-
end
|
434
|
-
|
435
|
-
def test_destroy_by_single_id_is_paranoid
|
436
|
-
model = ParanoidBelongsDependant.create
|
437
|
-
ParanoidBelongsDependant.destroy(model.id)
|
438
|
-
|
439
|
-
assert_paranoid_deletion(model)
|
440
|
-
end
|
441
|
-
|
442
|
-
def test_instance_delete_is_paranoid
|
443
|
-
model = ParanoidBelongsDependant.create
|
444
|
-
model.delete
|
445
|
-
|
446
|
-
assert_paranoid_deletion(model)
|
447
|
-
end
|
448
|
-
|
449
|
-
def test_instance_destroy_is_paranoid
|
450
|
-
model = ParanoidBelongsDependant.create
|
451
|
-
model.destroy
|
452
|
-
|
453
|
-
assert_paranoid_deletion(model)
|
454
|
-
end
|
455
|
-
|
456
|
-
# Test string type columns that don't have a nil value when not deleted (Y/N for example)
|
457
|
-
def test_string_type_with_no_nil_value_before_destroy
|
458
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
459
|
-
assert_equal 1, ParanoidString.where(id: ps).count
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_string_type_with_no_nil_value_after_destroy
|
463
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
464
|
-
ps.destroy
|
465
|
-
assert_equal 0, ParanoidString.where(id: ps).count
|
466
|
-
end
|
467
|
-
|
468
|
-
def test_string_type_with_no_nil_value_before_destroy_with_deleted
|
469
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
470
|
-
assert_equal 1, ParanoidString.with_deleted.where(id: ps).count
|
471
|
-
end
|
472
|
-
|
473
|
-
def test_string_type_with_no_nil_value_after_destroy_with_deleted
|
474
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
475
|
-
ps.destroy
|
476
|
-
assert_equal 1, ParanoidString.with_deleted.where(id: ps).count
|
477
|
-
end
|
478
|
-
|
479
|
-
def test_string_type_with_no_nil_value_before_destroy_only_deleted
|
480
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
481
|
-
assert_equal 0, ParanoidString.only_deleted.where(id: ps).count
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_string_type_with_no_nil_value_after_destroy_only_deleted
|
485
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
486
|
-
ps.destroy
|
487
|
-
assert_equal 1, ParanoidString.only_deleted.where(id: ps).count
|
488
|
-
end
|
489
|
-
|
490
|
-
def test_string_type_with_no_nil_value_after_destroyed_twice
|
491
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
492
|
-
2.times { ps.destroy }
|
493
|
-
assert_equal 0, ParanoidString.with_deleted.where(id: ps).count
|
494
|
-
end
|
495
|
-
|
496
|
-
# Test boolean type columns, that are not nullable
|
497
|
-
def test_boolean_type_with_no_nil_value_before_destroy
|
498
|
-
ps = ParanoidBooleanNotNullable.create!
|
499
|
-
assert_equal 1, ParanoidBooleanNotNullable.where(id: ps).count
|
500
|
-
end
|
501
|
-
|
502
|
-
def test_boolean_type_with_no_nil_value_after_destroy
|
503
|
-
ps = ParanoidBooleanNotNullable.create!
|
504
|
-
ps.destroy
|
505
|
-
assert_equal 0, ParanoidBooleanNotNullable.where(id: ps).count
|
506
|
-
end
|
507
|
-
|
508
|
-
def test_boolean_type_with_no_nil_value_before_destroy_with_deleted
|
509
|
-
ps = ParanoidBooleanNotNullable.create!
|
510
|
-
assert_equal 1, ParanoidBooleanNotNullable.with_deleted.where(id: ps).count
|
511
|
-
end
|
512
|
-
|
513
|
-
def test_boolean_type_with_no_nil_value_after_destroy_with_deleted
|
514
|
-
ps = ParanoidBooleanNotNullable.create!
|
515
|
-
ps.destroy
|
516
|
-
assert_equal 1, ParanoidBooleanNotNullable.with_deleted.where(id: ps).count
|
517
|
-
end
|
518
|
-
|
519
|
-
def test_boolean_type_with_no_nil_value_before_destroy_only_deleted
|
520
|
-
ps = ParanoidBooleanNotNullable.create!
|
521
|
-
assert_equal 0, ParanoidBooleanNotNullable.only_deleted.where(id: ps).count
|
522
|
-
end
|
523
|
-
|
524
|
-
def test_boolean_type_with_no_nil_value_after_destroy_only_deleted
|
525
|
-
ps = ParanoidBooleanNotNullable.create!
|
526
|
-
ps.destroy
|
527
|
-
assert_equal 1, ParanoidBooleanNotNullable.only_deleted.where(id: ps).count
|
528
|
-
end
|
529
|
-
|
530
|
-
def test_boolean_type_with_no_nil_value_after_destroyed_twice
|
531
|
-
ps = ParanoidBooleanNotNullable.create!
|
532
|
-
2.times { ps.destroy }
|
533
|
-
assert_equal 0, ParanoidBooleanNotNullable.with_deleted.where(id: ps).count
|
534
|
-
end
|
535
|
-
|
536
|
-
def test_no_double_tap_destroys_fully
|
537
|
-
ps = ParanoidNoDoubleTapDestroysFully.create!
|
538
|
-
2.times { ps.destroy }
|
539
|
-
assert_equal 1, ParanoidNoDoubleTapDestroysFully.with_deleted.where(id: ps).count
|
540
|
-
end
|
541
|
-
|
542
|
-
def test_decrement_counters
|
543
|
-
paranoid_boolean = ParanoidBoolean.create!
|
544
|
-
paranoid_with_counter_cache = ParanoidWithCounterCache
|
545
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
546
|
-
|
547
|
-
assert_equal 1, paranoid_boolean.paranoid_with_counter_caches_count
|
548
|
-
|
549
|
-
paranoid_with_counter_cache.destroy
|
550
|
-
|
551
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
552
|
-
end
|
553
|
-
|
554
|
-
def test_decrement_custom_counters
|
555
|
-
paranoid_boolean = ParanoidBoolean.create!
|
556
|
-
paranoid_with_custom_counter_cache = ParanoidWithCustomCounterCache
|
557
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
558
|
-
|
559
|
-
assert_equal 1, paranoid_boolean.custom_counter_cache
|
560
|
-
|
561
|
-
paranoid_with_custom_counter_cache.destroy
|
562
|
-
|
563
|
-
assert_equal 0, paranoid_boolean.reload.custom_counter_cache
|
564
|
-
end
|
565
|
-
|
566
|
-
def test_destroy_with_optional_belongs_to_and_counter_cache
|
567
|
-
ps = ParanoidWithCounterCacheOnOptionalBelognsTo.create!
|
568
|
-
ps.destroy
|
569
|
-
assert_equal 1, ParanoidWithCounterCacheOnOptionalBelognsTo.only_deleted
|
570
|
-
.where(id: ps).count
|
571
|
-
end
|
572
|
-
|
573
|
-
def test_hard_destroy_decrement_counters
|
574
|
-
paranoid_boolean = ParanoidBoolean.create!
|
575
|
-
paranoid_with_counter_cache = ParanoidWithCounterCache
|
576
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
577
|
-
|
578
|
-
assert_equal 1, paranoid_boolean.paranoid_with_counter_caches_count
|
579
|
-
|
580
|
-
paranoid_with_counter_cache.destroy_fully!
|
581
|
-
|
582
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
583
|
-
end
|
584
|
-
|
585
|
-
def test_hard_destroy_decrement_custom_counters
|
586
|
-
paranoid_boolean = ParanoidBoolean.create!
|
587
|
-
paranoid_with_custom_counter_cache = ParanoidWithCustomCounterCache
|
588
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
589
|
-
|
590
|
-
assert_equal 1, paranoid_boolean.custom_counter_cache
|
591
|
-
|
592
|
-
paranoid_with_custom_counter_cache.destroy_fully!
|
593
|
-
|
594
|
-
assert_equal 0, paranoid_boolean.reload.custom_counter_cache
|
595
|
-
end
|
596
|
-
|
597
|
-
def test_increment_counters
|
598
|
-
paranoid_boolean = ParanoidBoolean.create!
|
599
|
-
paranoid_with_counter_cache = ParanoidWithCounterCache
|
600
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
601
|
-
|
602
|
-
assert_equal 1, paranoid_boolean.paranoid_with_counter_caches_count
|
603
|
-
|
604
|
-
paranoid_with_counter_cache.destroy
|
605
|
-
|
606
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
607
|
-
|
608
|
-
paranoid_with_counter_cache.recover
|
609
|
-
|
610
|
-
assert_equal 1, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
611
|
-
end
|
612
|
-
|
613
|
-
def test_increment_custom_counters
|
614
|
-
paranoid_boolean = ParanoidBoolean.create!
|
615
|
-
paranoid_with_custom_counter_cache = ParanoidWithCustomCounterCache
|
616
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
617
|
-
|
618
|
-
assert_equal 1, paranoid_boolean.custom_counter_cache
|
619
|
-
|
620
|
-
paranoid_with_custom_counter_cache.destroy
|
621
|
-
|
622
|
-
assert_equal 0, paranoid_boolean.reload.custom_counter_cache
|
623
|
-
|
624
|
-
paranoid_with_custom_counter_cache.recover
|
625
|
-
|
626
|
-
assert_equal 1, paranoid_boolean.reload.custom_counter_cache
|
627
|
-
end
|
628
|
-
|
629
|
-
def test_explicitly_setting_table_name_after_acts_as_paranoid_macro
|
630
|
-
assert_equal "explicit_table.deleted_at", ParanoidWithExplicitTableNameAfterMacro
|
631
|
-
.paranoid_column_reference
|
632
|
-
end
|
633
|
-
end
|
data/test/test_default_scopes.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class MultipleDefaultScopesTest < ParanoidBaseTest
|
6
|
-
def setup
|
7
|
-
setup_db
|
8
|
-
|
9
|
-
ParanoidPolygon.create! sides: 3
|
10
|
-
ParanoidPolygon.create! sides: 3
|
11
|
-
ParanoidPolygon.create! sides: 3
|
12
|
-
ParanoidPolygon.create! sides: 8
|
13
|
-
|
14
|
-
assert_equal 3, ParanoidPolygon.count
|
15
|
-
assert_equal 4, ParanoidPolygon.unscoped.count
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_fake_removal_with_multiple_default_scope
|
19
|
-
ParanoidPolygon.first.destroy
|
20
|
-
assert_equal 2, ParanoidPolygon.count
|
21
|
-
assert_equal 3, ParanoidPolygon.with_deleted.count
|
22
|
-
assert_equal 1, ParanoidPolygon.only_deleted.count
|
23
|
-
assert_equal 4, ParanoidPolygon.unscoped.count
|
24
|
-
|
25
|
-
ParanoidPolygon.destroy_all
|
26
|
-
assert_equal 0, ParanoidPolygon.count
|
27
|
-
assert_equal 3, ParanoidPolygon.with_deleted.count
|
28
|
-
assert_equal 3, ParanoidPolygon.with_deleted.count
|
29
|
-
assert_equal 4, ParanoidPolygon.unscoped.count
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_real_removal_with_multiple_default_scope
|
33
|
-
# two-step
|
34
|
-
ParanoidPolygon.first.destroy
|
35
|
-
ParanoidPolygon.only_deleted.first.destroy
|
36
|
-
assert_equal 2, ParanoidPolygon.count
|
37
|
-
assert_equal 2, ParanoidPolygon.with_deleted.count
|
38
|
-
assert_equal 0, ParanoidPolygon.only_deleted.count
|
39
|
-
assert_equal 3, ParanoidPolygon.unscoped.count
|
40
|
-
|
41
|
-
ParanoidPolygon.first.destroy_fully!
|
42
|
-
assert_equal 1, ParanoidPolygon.count
|
43
|
-
assert_equal 1, ParanoidPolygon.with_deleted.count
|
44
|
-
assert_equal 0, ParanoidPolygon.only_deleted.count
|
45
|
-
assert_equal 2, ParanoidPolygon.unscoped.count
|
46
|
-
|
47
|
-
ParanoidPolygon.delete_all!
|
48
|
-
assert_equal 0, ParanoidPolygon.count
|
49
|
-
assert_equal 0, ParanoidPolygon.with_deleted.count
|
50
|
-
assert_equal 0, ParanoidPolygon.only_deleted.count
|
51
|
-
assert_equal 1, ParanoidPolygon.unscoped.count
|
52
|
-
end
|
53
|
-
end
|