acts_as_paranoid 0.7.3 → 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 +22 -0
- data/CONTRIBUTING.md +9 -10
- data/README.md +3 -3
- data/lib/acts_as_paranoid/core.rb +30 -28
- data/lib/acts_as_paranoid/relation.rb +0 -7
- data/lib/acts_as_paranoid/version.rb +1 -1
- data/lib/acts_as_paranoid.rb +3 -2
- metadata +56 -73
- data/test/test_associations.rb +0 -354
- data/test/test_core.rb +0 -736
- data/test/test_default_scopes.rb +0 -64
- data/test/test_dependent_recovery.rb +0 -54
- data/test/test_deprecated_behavior.rb +0 -30
- data/test/test_helper.rb +0 -554
- data/test/test_inheritance.rb +0 -16
- data/test/test_relations.rb +0 -199
- data/test/test_table_namespace.rb +0 -40
- data/test/test_validations.rb +0 -63
data/test/test_core.rb
DELETED
@@ -1,736 +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
|
-
def test_recover_has_one_association
|
116
|
-
parent = ParanoidBoolean.create(name: "parent")
|
117
|
-
child = parent.create_paranoid_has_one_dependant(name: "child")
|
118
|
-
|
119
|
-
parent.destroy
|
120
|
-
assert parent.paranoid_has_one_dependant.destroyed?
|
121
|
-
|
122
|
-
parent.recover
|
123
|
-
refute parent.paranoid_has_one_dependant.destroyed?
|
124
|
-
|
125
|
-
child.reload
|
126
|
-
refute child.destroyed?
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_recover_has_many_association
|
130
|
-
parent = ParanoidTime.create(name: "parent")
|
131
|
-
child = parent.paranoid_has_many_dependants.create(name: "child")
|
132
|
-
|
133
|
-
parent.destroy
|
134
|
-
assert child.destroyed?
|
135
|
-
|
136
|
-
parent.recover
|
137
|
-
assert_equal 1, parent.paranoid_has_many_dependants.count
|
138
|
-
|
139
|
-
child.reload
|
140
|
-
refute child.destroyed?
|
141
|
-
end
|
142
|
-
|
143
|
-
# Rails does not allow saving deleted records
|
144
|
-
def test_no_save_after_destroy
|
145
|
-
paranoid = ParanoidString.first
|
146
|
-
paranoid.destroy
|
147
|
-
paranoid.name = "Let's update!"
|
148
|
-
|
149
|
-
assert_not paranoid.save
|
150
|
-
assert_raises ActiveRecord::RecordNotSaved do
|
151
|
-
paranoid.save!
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_scope_chaining
|
156
|
-
assert_equal 3, ParanoidBoolean.unscoped.with_deleted.count
|
157
|
-
assert_equal 0, ParanoidBoolean.unscoped.only_deleted.count
|
158
|
-
assert_equal 0, ParanoidBoolean.with_deleted.only_deleted.count
|
159
|
-
assert_equal 3, ParanoidBoolean.with_deleted.with_deleted.count
|
160
|
-
end
|
161
|
-
|
162
|
-
def setup_recursive_tests
|
163
|
-
@paranoid_time_object = ParanoidTime.first
|
164
|
-
|
165
|
-
# Create one extra ParanoidHasManyDependant record so that we can validate
|
166
|
-
# the correct dependants are recovered.
|
167
|
-
ParanoidTime.where("id <> ?", @paranoid_time_object.id).first
|
168
|
-
.paranoid_has_many_dependants.create(name: "should not be recovered").destroy
|
169
|
-
|
170
|
-
@paranoid_boolean_count = ParanoidBoolean.count
|
171
|
-
|
172
|
-
assert_equal 0, ParanoidHasManyDependant.count
|
173
|
-
assert_equal 0, ParanoidBelongsDependant.count
|
174
|
-
assert_equal 1, NotParanoid.count
|
175
|
-
|
176
|
-
(1..3).each do |i|
|
177
|
-
has_many_object = @paranoid_time_object.paranoid_has_many_dependants
|
178
|
-
.create(name: "has_many_#{i}")
|
179
|
-
has_many_object.create_paranoid_belongs_dependant(name: "belongs_to_#{i}")
|
180
|
-
has_many_object.save
|
181
|
-
|
182
|
-
paranoid_boolean = @paranoid_time_object.paranoid_booleans
|
183
|
-
.create(name: "boolean_#{i}")
|
184
|
-
paranoid_boolean.create_paranoid_has_one_dependant(name: "has_one_#{i}")
|
185
|
-
paranoid_boolean.save
|
186
|
-
|
187
|
-
@paranoid_time_object.not_paranoids.create(name: "not_paranoid_a#{i}")
|
188
|
-
end
|
189
|
-
|
190
|
-
@paranoid_time_object.create_not_paranoid(name: "not_paranoid_belongs_to")
|
191
|
-
@paranoid_time_object.create_has_one_not_paranoid(name: "has_one_not_paranoid")
|
192
|
-
|
193
|
-
assert_equal 3, ParanoidTime.count
|
194
|
-
assert_equal 3, ParanoidHasManyDependant.count
|
195
|
-
assert_equal 3, ParanoidBelongsDependant.count
|
196
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
|
197
|
-
assert_equal 3, ParanoidHasOneDependant.count
|
198
|
-
assert_equal 5, NotParanoid.count
|
199
|
-
assert_equal 1, HasOneNotParanoid.count
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_recursive_fake_removal
|
203
|
-
setup_recursive_tests
|
204
|
-
|
205
|
-
@paranoid_time_object.destroy
|
206
|
-
|
207
|
-
assert_equal 2, ParanoidTime.count
|
208
|
-
assert_equal 0, ParanoidHasManyDependant.count
|
209
|
-
assert_equal 0, ParanoidBelongsDependant.count
|
210
|
-
assert_equal @paranoid_boolean_count, ParanoidBoolean.count
|
211
|
-
assert_equal 0, ParanoidHasOneDependant.count
|
212
|
-
assert_equal 1, NotParanoid.count
|
213
|
-
assert_equal 0, HasOneNotParanoid.count
|
214
|
-
|
215
|
-
assert_equal 3, ParanoidTime.with_deleted.count
|
216
|
-
assert_equal 4, ParanoidHasManyDependant.with_deleted.count
|
217
|
-
assert_equal 3, ParanoidBelongsDependant.with_deleted.count
|
218
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.with_deleted.count
|
219
|
-
assert_equal 3, ParanoidHasOneDependant.with_deleted.count
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_recursive_real_removal
|
223
|
-
setup_recursive_tests
|
224
|
-
|
225
|
-
@paranoid_time_object.destroy_fully!
|
226
|
-
|
227
|
-
assert_equal 0, ParanoidTime.only_deleted.count
|
228
|
-
assert_equal 1, ParanoidHasManyDependant.only_deleted.count
|
229
|
-
assert_equal 0, ParanoidBelongsDependant.only_deleted.count
|
230
|
-
assert_equal 0, ParanoidBoolean.only_deleted.count
|
231
|
-
assert_equal 0, ParanoidHasOneDependant.only_deleted.count
|
232
|
-
assert_equal 1, NotParanoid.count
|
233
|
-
assert_equal 0, HasOneNotParanoid.count
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_recursive_recovery
|
237
|
-
setup_recursive_tests
|
238
|
-
|
239
|
-
@paranoid_time_object.destroy
|
240
|
-
@paranoid_time_object.reload
|
241
|
-
|
242
|
-
@paranoid_time_object.recover(recursive: true)
|
243
|
-
|
244
|
-
assert_equal 3, ParanoidTime.count
|
245
|
-
assert_equal 3, ParanoidHasManyDependant.count
|
246
|
-
assert_equal 3, ParanoidBelongsDependant.count
|
247
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
|
248
|
-
assert_equal 3, ParanoidHasOneDependant.count
|
249
|
-
assert_equal 1, NotParanoid.count
|
250
|
-
assert_equal 0, HasOneNotParanoid.count
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_recursive_recovery_dependant_window
|
254
|
-
setup_recursive_tests
|
255
|
-
|
256
|
-
# Stop the following from recovering:
|
257
|
-
# - ParanoidHasManyDependant and its ParanoidBelongsDependant
|
258
|
-
# - A single ParanoidBelongsDependant, but not its parent
|
259
|
-
Time.stub :now, 2.days.ago do
|
260
|
-
@paranoid_time_object.paranoid_has_many_dependants.first.destroy
|
261
|
-
end
|
262
|
-
Time.stub :now, 1.hour.ago do
|
263
|
-
@paranoid_time_object.paranoid_has_many_dependants
|
264
|
-
.last.paranoid_belongs_dependant
|
265
|
-
.destroy
|
266
|
-
end
|
267
|
-
@paranoid_time_object.destroy
|
268
|
-
@paranoid_time_object.reload
|
269
|
-
|
270
|
-
@paranoid_time_object.recover(recursive: true)
|
271
|
-
|
272
|
-
assert_equal 3, ParanoidTime.count
|
273
|
-
assert_equal 2, ParanoidHasManyDependant.count
|
274
|
-
assert_equal 1, ParanoidBelongsDependant.count
|
275
|
-
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
|
276
|
-
assert_equal 3, ParanoidHasOneDependant.count
|
277
|
-
assert_equal 1, NotParanoid.count
|
278
|
-
assert_equal 0, HasOneNotParanoid.count
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_recursive_recovery_for_belongs_to_polymorphic
|
282
|
-
child_1 = ParanoidAndroid.create
|
283
|
-
section_1 = ParanoidSection.create(paranoid_thing: child_1)
|
284
|
-
|
285
|
-
child_2 = ParanoidPolygon.create(sides: 3)
|
286
|
-
section_2 = ParanoidSection.create(paranoid_thing: child_2)
|
287
|
-
|
288
|
-
assert_equal section_1.paranoid_thing, child_1
|
289
|
-
assert_equal section_1.paranoid_thing.class, ParanoidAndroid
|
290
|
-
assert_equal section_2.paranoid_thing, child_2
|
291
|
-
assert_equal section_2.paranoid_thing.class, ParanoidPolygon
|
292
|
-
|
293
|
-
parent = ParanoidTime.create(name: "paranoid_parent")
|
294
|
-
parent.paranoid_sections << section_1
|
295
|
-
parent.paranoid_sections << section_2
|
296
|
-
|
297
|
-
assert_equal 4, ParanoidTime.count
|
298
|
-
assert_equal 2, ParanoidSection.count
|
299
|
-
assert_equal 1, ParanoidAndroid.count
|
300
|
-
assert_equal 1, ParanoidPolygon.count
|
301
|
-
|
302
|
-
parent.destroy
|
303
|
-
|
304
|
-
assert_equal 3, ParanoidTime.count
|
305
|
-
assert_equal 0, ParanoidSection.count
|
306
|
-
assert_equal 0, ParanoidAndroid.count
|
307
|
-
assert_equal 0, ParanoidPolygon.count
|
308
|
-
|
309
|
-
parent.reload
|
310
|
-
parent.recover
|
311
|
-
|
312
|
-
assert_equal 4, ParanoidTime.count
|
313
|
-
assert_equal 2, ParanoidSection.count
|
314
|
-
assert_equal 1, ParanoidAndroid.count
|
315
|
-
assert_equal 1, ParanoidPolygon.count
|
316
|
-
end
|
317
|
-
|
318
|
-
def test_non_recursive_recovery
|
319
|
-
setup_recursive_tests
|
320
|
-
|
321
|
-
@paranoid_time_object.destroy
|
322
|
-
@paranoid_time_object.reload
|
323
|
-
|
324
|
-
@paranoid_time_object.recover(recursive: false)
|
325
|
-
|
326
|
-
assert_equal 3, ParanoidTime.count
|
327
|
-
assert_equal 0, ParanoidHasManyDependant.count
|
328
|
-
assert_equal 0, ParanoidBelongsDependant.count
|
329
|
-
assert_equal @paranoid_boolean_count, ParanoidBoolean.count
|
330
|
-
assert_equal 0, ParanoidHasOneDependant.count
|
331
|
-
assert_equal 1, NotParanoid.count
|
332
|
-
assert_equal 0, HasOneNotParanoid.count
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_dirty
|
336
|
-
pt = ParanoidTime.create
|
337
|
-
pt.destroy
|
338
|
-
assert_not pt.changed?
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_delete_dirty
|
342
|
-
pt = ParanoidTime.create
|
343
|
-
pt.delete
|
344
|
-
assert_not pt.changed?
|
345
|
-
end
|
346
|
-
|
347
|
-
def test_destroy_fully_dirty
|
348
|
-
pt = ParanoidTime.create
|
349
|
-
pt.destroy_fully!
|
350
|
-
assert_not pt.changed?
|
351
|
-
end
|
352
|
-
|
353
|
-
def test_deleted?
|
354
|
-
ParanoidTime.first.destroy
|
355
|
-
assert ParanoidTime.with_deleted.first.deleted?
|
356
|
-
|
357
|
-
ParanoidString.first.destroy
|
358
|
-
assert ParanoidString.with_deleted.first.deleted?
|
359
|
-
end
|
360
|
-
|
361
|
-
def test_delete_deleted?
|
362
|
-
ParanoidTime.first.delete
|
363
|
-
assert ParanoidTime.with_deleted.first.deleted?
|
364
|
-
|
365
|
-
ParanoidString.first.delete
|
366
|
-
assert ParanoidString.with_deleted.first.deleted?
|
367
|
-
end
|
368
|
-
|
369
|
-
def test_destroy_fully_deleted?
|
370
|
-
object = ParanoidTime.first
|
371
|
-
object.destroy_fully!
|
372
|
-
assert object.deleted?
|
373
|
-
|
374
|
-
object = ParanoidString.first
|
375
|
-
object.destroy_fully!
|
376
|
-
assert object.deleted?
|
377
|
-
end
|
378
|
-
|
379
|
-
def test_deleted_fully?
|
380
|
-
ParanoidTime.first.destroy
|
381
|
-
assert_not ParanoidTime.with_deleted.first.deleted_fully?
|
382
|
-
|
383
|
-
ParanoidString.first.destroy
|
384
|
-
assert ParanoidString.with_deleted.first.deleted?
|
385
|
-
end
|
386
|
-
|
387
|
-
def test_delete_deleted_fully?
|
388
|
-
ParanoidTime.first.delete
|
389
|
-
assert_not ParanoidTime.with_deleted.first.deleted_fully?
|
390
|
-
end
|
391
|
-
|
392
|
-
def test_destroy_fully_deleted_fully?
|
393
|
-
object = ParanoidTime.first
|
394
|
-
object.destroy_fully!
|
395
|
-
assert object.deleted_fully?
|
396
|
-
end
|
397
|
-
|
398
|
-
def test_paranoid_destroy_callbacks
|
399
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
400
|
-
ParanoidWithCallback.transaction do
|
401
|
-
@paranoid_with_callback.destroy
|
402
|
-
end
|
403
|
-
|
404
|
-
assert @paranoid_with_callback.called_before_destroy
|
405
|
-
assert @paranoid_with_callback.called_after_destroy
|
406
|
-
assert @paranoid_with_callback.called_after_commit_on_destroy
|
407
|
-
end
|
408
|
-
|
409
|
-
def test_hard_destroy_callbacks
|
410
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
411
|
-
|
412
|
-
ParanoidWithCallback.transaction do
|
413
|
-
@paranoid_with_callback.destroy!
|
414
|
-
end
|
415
|
-
|
416
|
-
assert @paranoid_with_callback.called_before_destroy
|
417
|
-
assert @paranoid_with_callback.called_after_destroy
|
418
|
-
assert @paranoid_with_callback.called_after_commit_on_destroy
|
419
|
-
end
|
420
|
-
|
421
|
-
def test_recovery_callbacks
|
422
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
423
|
-
|
424
|
-
ParanoidWithCallback.transaction do
|
425
|
-
@paranoid_with_callback.destroy
|
426
|
-
|
427
|
-
assert_nil @paranoid_with_callback.called_before_recover
|
428
|
-
assert_nil @paranoid_with_callback.called_after_recover
|
429
|
-
|
430
|
-
@paranoid_with_callback.recover
|
431
|
-
end
|
432
|
-
|
433
|
-
assert @paranoid_with_callback.called_before_recover
|
434
|
-
assert @paranoid_with_callback.called_after_recover
|
435
|
-
end
|
436
|
-
|
437
|
-
def test_recovery_callbacks_without_destroy
|
438
|
-
@paranoid_with_callback = ParanoidWithCallback.first
|
439
|
-
@paranoid_with_callback.recover
|
440
|
-
|
441
|
-
assert_nil @paranoid_with_callback.called_before_recover
|
442
|
-
assert_nil @paranoid_with_callback.called_after_recover
|
443
|
-
end
|
444
|
-
|
445
|
-
def test_delete_by_multiple_id_is_paranoid
|
446
|
-
model_a = ParanoidBelongsDependant.create
|
447
|
-
model_b = ParanoidBelongsDependant.create
|
448
|
-
ParanoidBelongsDependant.delete([model_a.id, model_b.id])
|
449
|
-
|
450
|
-
assert_paranoid_deletion(model_a)
|
451
|
-
assert_paranoid_deletion(model_b)
|
452
|
-
end
|
453
|
-
|
454
|
-
def test_destroy_by_multiple_id_is_paranoid
|
455
|
-
model_a = ParanoidBelongsDependant.create
|
456
|
-
model_b = ParanoidBelongsDependant.create
|
457
|
-
ParanoidBelongsDependant.destroy([model_a.id, model_b.id])
|
458
|
-
|
459
|
-
assert_paranoid_deletion(model_a)
|
460
|
-
assert_paranoid_deletion(model_b)
|
461
|
-
end
|
462
|
-
|
463
|
-
def test_delete_by_single_id_is_paranoid
|
464
|
-
model = ParanoidBelongsDependant.create
|
465
|
-
ParanoidBelongsDependant.delete(model.id)
|
466
|
-
|
467
|
-
assert_paranoid_deletion(model)
|
468
|
-
end
|
469
|
-
|
470
|
-
def test_destroy_by_single_id_is_paranoid
|
471
|
-
model = ParanoidBelongsDependant.create
|
472
|
-
ParanoidBelongsDependant.destroy(model.id)
|
473
|
-
|
474
|
-
assert_paranoid_deletion(model)
|
475
|
-
end
|
476
|
-
|
477
|
-
def test_instance_delete_is_paranoid
|
478
|
-
model = ParanoidBelongsDependant.create
|
479
|
-
model.delete
|
480
|
-
|
481
|
-
assert_paranoid_deletion(model)
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_instance_destroy_is_paranoid
|
485
|
-
model = ParanoidBelongsDependant.create
|
486
|
-
model.destroy
|
487
|
-
|
488
|
-
assert_paranoid_deletion(model)
|
489
|
-
end
|
490
|
-
|
491
|
-
# Test string type columns that don't have a nil value when not deleted (Y/N for example)
|
492
|
-
def test_string_type_with_no_nil_value_before_destroy
|
493
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
494
|
-
assert_equal 1, ParanoidString.where(id: ps).count
|
495
|
-
end
|
496
|
-
|
497
|
-
def test_string_type_with_no_nil_value_after_destroy
|
498
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
499
|
-
ps.destroy
|
500
|
-
assert_equal 0, ParanoidString.where(id: ps).count
|
501
|
-
end
|
502
|
-
|
503
|
-
def test_string_type_with_no_nil_value_before_destroy_with_deleted
|
504
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
505
|
-
assert_equal 1, ParanoidString.with_deleted.where(id: ps).count
|
506
|
-
end
|
507
|
-
|
508
|
-
def test_string_type_with_no_nil_value_after_destroy_with_deleted
|
509
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
510
|
-
ps.destroy
|
511
|
-
assert_equal 1, ParanoidString.with_deleted.where(id: ps).count
|
512
|
-
end
|
513
|
-
|
514
|
-
def test_string_type_with_no_nil_value_before_destroy_only_deleted
|
515
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
516
|
-
assert_equal 0, ParanoidString.only_deleted.where(id: ps).count
|
517
|
-
end
|
518
|
-
|
519
|
-
def test_string_type_with_no_nil_value_after_destroy_only_deleted
|
520
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
521
|
-
ps.destroy
|
522
|
-
assert_equal 1, ParanoidString.only_deleted.where(id: ps).count
|
523
|
-
end
|
524
|
-
|
525
|
-
def test_string_type_with_no_nil_value_after_destroyed_twice
|
526
|
-
ps = ParanoidString.create!(deleted: "not dead")
|
527
|
-
2.times { ps.destroy }
|
528
|
-
assert_equal 0, ParanoidString.with_deleted.where(id: ps).count
|
529
|
-
end
|
530
|
-
|
531
|
-
# Test boolean type columns, that are not nullable
|
532
|
-
def test_boolean_type_with_no_nil_value_before_destroy
|
533
|
-
ps = ParanoidBooleanNotNullable.create!
|
534
|
-
assert_equal 1, ParanoidBooleanNotNullable.where(id: ps).count
|
535
|
-
end
|
536
|
-
|
537
|
-
def test_boolean_type_with_no_nil_value_after_destroy
|
538
|
-
ps = ParanoidBooleanNotNullable.create!
|
539
|
-
ps.destroy
|
540
|
-
assert_equal 0, ParanoidBooleanNotNullable.where(id: ps).count
|
541
|
-
end
|
542
|
-
|
543
|
-
def test_boolean_type_with_no_nil_value_before_destroy_with_deleted
|
544
|
-
ps = ParanoidBooleanNotNullable.create!
|
545
|
-
assert_equal 1, ParanoidBooleanNotNullable.with_deleted.where(id: ps).count
|
546
|
-
end
|
547
|
-
|
548
|
-
def test_boolean_type_with_no_nil_value_after_destroy_with_deleted
|
549
|
-
ps = ParanoidBooleanNotNullable.create!
|
550
|
-
ps.destroy
|
551
|
-
assert_equal 1, ParanoidBooleanNotNullable.with_deleted.where(id: ps).count
|
552
|
-
end
|
553
|
-
|
554
|
-
def test_boolean_type_with_no_nil_value_before_destroy_only_deleted
|
555
|
-
ps = ParanoidBooleanNotNullable.create!
|
556
|
-
assert_equal 0, ParanoidBooleanNotNullable.only_deleted.where(id: ps).count
|
557
|
-
end
|
558
|
-
|
559
|
-
def test_boolean_type_with_no_nil_value_after_destroy_only_deleted
|
560
|
-
ps = ParanoidBooleanNotNullable.create!
|
561
|
-
ps.destroy
|
562
|
-
assert_equal 1, ParanoidBooleanNotNullable.only_deleted.where(id: ps).count
|
563
|
-
end
|
564
|
-
|
565
|
-
def test_boolean_type_with_no_nil_value_after_destroyed_twice
|
566
|
-
ps = ParanoidBooleanNotNullable.create!
|
567
|
-
2.times { ps.destroy }
|
568
|
-
assert_equal 0, ParanoidBooleanNotNullable.with_deleted.where(id: ps).count
|
569
|
-
end
|
570
|
-
|
571
|
-
def test_boolean_type_with_no_nil_value_after_recover
|
572
|
-
ps = ParanoidBooleanNotNullable.create!
|
573
|
-
ps.destroy
|
574
|
-
assert_equal 1, ParanoidBooleanNotNullable.only_deleted.where(id: ps).count
|
575
|
-
|
576
|
-
ps.recover
|
577
|
-
assert_equal 1, ParanoidBooleanNotNullable.where(id: ps).count
|
578
|
-
end
|
579
|
-
|
580
|
-
def test_boolean_type_with_no_nil_value_after_recover!
|
581
|
-
ps = ParanoidBooleanNotNullable.create!
|
582
|
-
ps.destroy
|
583
|
-
assert_equal 1, ParanoidBooleanNotNullable.only_deleted.where(id: ps).count
|
584
|
-
|
585
|
-
ps.recover!
|
586
|
-
assert_equal 1, ParanoidBooleanNotNullable.where(id: ps).count
|
587
|
-
end
|
588
|
-
|
589
|
-
def test_no_double_tap_destroys_fully
|
590
|
-
ps = ParanoidNoDoubleTapDestroysFully.create!
|
591
|
-
2.times { ps.destroy }
|
592
|
-
assert_equal 1, ParanoidNoDoubleTapDestroysFully.with_deleted.where(id: ps).count
|
593
|
-
end
|
594
|
-
|
595
|
-
def test_decrement_counters_without_touch
|
596
|
-
paranoid_boolean = ParanoidBoolean.create!
|
597
|
-
paranoid_with_counter_cache = ParanoidWithCounterCache
|
598
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
599
|
-
|
600
|
-
assert_equal 1, paranoid_boolean.paranoid_with_counter_caches_count
|
601
|
-
updated_at = paranoid_boolean.reload.updated_at
|
602
|
-
|
603
|
-
paranoid_with_counter_cache.destroy
|
604
|
-
|
605
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
606
|
-
assert_equal updated_at, paranoid_boolean.reload.updated_at
|
607
|
-
end
|
608
|
-
|
609
|
-
def test_decrement_custom_counters
|
610
|
-
paranoid_boolean = ParanoidBoolean.create!
|
611
|
-
paranoid_with_custom_counter_cache = ParanoidWithCustomCounterCache
|
612
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
613
|
-
|
614
|
-
assert_equal 1, paranoid_boolean.custom_counter_cache
|
615
|
-
|
616
|
-
paranoid_with_custom_counter_cache.destroy
|
617
|
-
|
618
|
-
assert_equal 0, paranoid_boolean.reload.custom_counter_cache
|
619
|
-
end
|
620
|
-
|
621
|
-
def test_decrement_counters_with_touch
|
622
|
-
paranoid_boolean = ParanoidBoolean.create!
|
623
|
-
paranoid_with_counter_cache = ParanoidWithTouchAndCounterCache
|
624
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
625
|
-
|
626
|
-
assert_equal 1, paranoid_boolean.paranoid_with_touch_and_counter_caches_count
|
627
|
-
updated_at = paranoid_boolean.reload.updated_at
|
628
|
-
|
629
|
-
paranoid_with_counter_cache.destroy
|
630
|
-
|
631
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_touch_and_counter_caches_count
|
632
|
-
assert_not_equal updated_at, paranoid_boolean.reload.updated_at
|
633
|
-
end
|
634
|
-
|
635
|
-
def test_touch_belongs_to
|
636
|
-
paranoid_boolean = ParanoidBoolean.create!
|
637
|
-
paranoid_with_counter_cache = ParanoidWithTouch
|
638
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
639
|
-
|
640
|
-
updated_at = paranoid_boolean.reload.updated_at
|
641
|
-
|
642
|
-
paranoid_with_counter_cache.destroy
|
643
|
-
|
644
|
-
assert_not_equal updated_at, paranoid_boolean.reload.updated_at
|
645
|
-
end
|
646
|
-
|
647
|
-
def test_destroy_with_optional_belongs_to_and_counter_cache
|
648
|
-
ps = ParanoidWithCounterCacheOnOptionalBelognsTo.create!
|
649
|
-
ps.destroy
|
650
|
-
assert_equal 1, ParanoidWithCounterCacheOnOptionalBelognsTo.only_deleted
|
651
|
-
.where(id: ps).count
|
652
|
-
end
|
653
|
-
|
654
|
-
def test_hard_destroy_decrement_counters
|
655
|
-
paranoid_boolean = ParanoidBoolean.create!
|
656
|
-
paranoid_with_counter_cache = ParanoidWithCounterCache
|
657
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
658
|
-
|
659
|
-
assert_equal 1, paranoid_boolean.paranoid_with_counter_caches_count
|
660
|
-
|
661
|
-
paranoid_with_counter_cache.destroy_fully!
|
662
|
-
|
663
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
664
|
-
end
|
665
|
-
|
666
|
-
def test_hard_destroy_decrement_custom_counters
|
667
|
-
paranoid_boolean = ParanoidBoolean.create!
|
668
|
-
paranoid_with_custom_counter_cache = ParanoidWithCustomCounterCache
|
669
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
670
|
-
|
671
|
-
assert_equal 1, paranoid_boolean.custom_counter_cache
|
672
|
-
|
673
|
-
paranoid_with_custom_counter_cache.destroy_fully!
|
674
|
-
|
675
|
-
assert_equal 0, paranoid_boolean.reload.custom_counter_cache
|
676
|
-
end
|
677
|
-
|
678
|
-
def test_increment_counters
|
679
|
-
paranoid_boolean = ParanoidBoolean.create!
|
680
|
-
paranoid_with_counter_cache = ParanoidWithCounterCache
|
681
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
682
|
-
|
683
|
-
assert_equal 1, paranoid_boolean.paranoid_with_counter_caches_count
|
684
|
-
|
685
|
-
paranoid_with_counter_cache.destroy
|
686
|
-
|
687
|
-
assert_equal 0, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
688
|
-
|
689
|
-
paranoid_with_counter_cache.recover
|
690
|
-
|
691
|
-
assert_equal 1, paranoid_boolean.reload.paranoid_with_counter_caches_count
|
692
|
-
end
|
693
|
-
|
694
|
-
def test_increment_custom_counters
|
695
|
-
paranoid_boolean = ParanoidBoolean.create!
|
696
|
-
paranoid_with_custom_counter_cache = ParanoidWithCustomCounterCache
|
697
|
-
.create!(paranoid_boolean: paranoid_boolean)
|
698
|
-
|
699
|
-
assert_equal 1, paranoid_boolean.custom_counter_cache
|
700
|
-
|
701
|
-
paranoid_with_custom_counter_cache.destroy
|
702
|
-
|
703
|
-
assert_equal 0, paranoid_boolean.reload.custom_counter_cache
|
704
|
-
|
705
|
-
paranoid_with_custom_counter_cache.recover
|
706
|
-
|
707
|
-
assert_equal 1, paranoid_boolean.reload.custom_counter_cache
|
708
|
-
end
|
709
|
-
|
710
|
-
def test_explicitly_setting_table_name_after_acts_as_paranoid_macro
|
711
|
-
assert_equal "explicit_table.deleted_at", ParanoidWithExplicitTableNameAfterMacro
|
712
|
-
.paranoid_column_reference
|
713
|
-
end
|
714
|
-
|
715
|
-
def test_deleted_after_time
|
716
|
-
ParanoidTime.first.destroy
|
717
|
-
assert_equal 0, ParanoidTime.deleted_after_time(1.hour.from_now).count
|
718
|
-
assert_equal 1, ParanoidTime.deleted_after_time(1.hour.ago).count
|
719
|
-
end
|
720
|
-
|
721
|
-
def test_deleted_before_time
|
722
|
-
ParanoidTime.first.destroy
|
723
|
-
assert_equal 1, ParanoidTime.deleted_before_time(1.hour.from_now).count
|
724
|
-
assert_equal 0, ParanoidTime.deleted_before_time(1.hour.ago).count
|
725
|
-
end
|
726
|
-
|
727
|
-
def test_deleted_inside_time_window
|
728
|
-
ParanoidTime.first.destroy
|
729
|
-
assert_equal 1, ParanoidTime.deleted_inside_time_window(1.minute.ago, 2.minutes).count
|
730
|
-
assert_equal 1,
|
731
|
-
ParanoidTime.deleted_inside_time_window(1.minute.from_now, 2.minutes).count
|
732
|
-
assert_equal 0, ParanoidTime.deleted_inside_time_window(3.minutes.ago, 1.minute).count
|
733
|
-
assert_equal 0,
|
734
|
-
ParanoidTime.deleted_inside_time_window(3.minutes.from_now, 1.minute).count
|
735
|
-
end
|
736
|
-
end
|