acts_as_paranoid 0.7.2 → 0.8.1

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.
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class RelationsTest < ParanoidBaseTest
6
- def setup
7
- setup_db
8
-
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
12
-
13
- assert_equal 3, ParanoidForest.count
14
- assert_equal 2, ParanoidForest.rainforest.count
15
-
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"
20
-
21
- assert_equal 4, ParanoidTree.count
22
- end
23
-
24
- def test_filtering_with_scopes
25
- assert_equal 2, ParanoidForest.rainforest.with_deleted.count
26
- assert_equal 2, ParanoidForest.with_deleted.rainforest.count
27
-
28
- assert_equal 0, ParanoidForest.rainforest.only_deleted.count
29
- assert_equal 0, ParanoidForest.only_deleted.rainforest.count
30
-
31
- ParanoidForest.rainforest.first.destroy
32
- assert_equal 1, ParanoidForest.rainforest.count
33
-
34
- assert_equal 2, ParanoidForest.rainforest.with_deleted.count
35
- assert_equal 2, ParanoidForest.with_deleted.rainforest.count
36
-
37
- assert_equal 1, ParanoidForest.rainforest.only_deleted.count
38
- assert_equal 1, ParanoidForest.only_deleted.rainforest.count
39
- end
40
-
41
- def test_associations_filtered_by_with_deleted
42
- assert_equal 2, @paranoid_forest_1.paranoid_trees.with_deleted.count
43
- assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
44
-
45
- @paranoid_forest_1.paranoid_trees.first.destroy
46
- assert_equal 1, @paranoid_forest_1.paranoid_trees.count
47
- assert_equal 2, @paranoid_forest_1.paranoid_trees.with_deleted.count
48
- assert_equal 4, ParanoidTree.with_deleted.count
49
-
50
- @paranoid_forest_2.paranoid_trees.first.destroy
51
- assert_equal 1, @paranoid_forest_2.paranoid_trees.count
52
- assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
53
- assert_equal 4, ParanoidTree.with_deleted.count
54
-
55
- @paranoid_forest_1.paranoid_trees.first.destroy
56
- assert_equal 0, @paranoid_forest_1.paranoid_trees.count
57
- assert_equal 2, @paranoid_forest_1.paranoid_trees.with_deleted.count
58
- assert_equal 4, ParanoidTree.with_deleted.count
59
- end
60
-
61
- def test_associations_filtered_by_only_deleted
62
- assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
63
- assert_equal 0, @paranoid_forest_2.paranoid_trees.only_deleted.count
64
-
65
- @paranoid_forest_1.paranoid_trees.first.destroy
66
- assert_equal 1, @paranoid_forest_1.paranoid_trees.only_deleted.count
67
- assert_equal 1, ParanoidTree.only_deleted.count
68
-
69
- @paranoid_forest_2.paranoid_trees.first.destroy
70
- assert_equal 1, @paranoid_forest_2.paranoid_trees.only_deleted.count
71
- assert_equal 2, ParanoidTree.only_deleted.count
72
-
73
- @paranoid_forest_1.paranoid_trees.first.destroy
74
- assert_equal 2, @paranoid_forest_1.paranoid_trees.only_deleted.count
75
- assert_equal 3, ParanoidTree.only_deleted.count
76
- end
77
-
78
- def test_fake_removal_through_relation
79
- # destroy: through a relation.
80
- ParanoidForest.rainforest.destroy(@paranoid_forest_3.id)
81
- assert_equal 1, ParanoidForest.rainforest.count
82
- assert_equal 2, ParanoidForest.rainforest.with_deleted.count
83
- assert_equal 1, ParanoidForest.rainforest.only_deleted.count
84
-
85
- # destroy_all: through a relation
86
- @paranoid_forest_2.paranoid_trees.order(:id).destroy_all
87
- assert_equal 0, @paranoid_forest_2.paranoid_trees.count
88
- assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
89
- end
90
-
91
- def test_real_removal_through_relation_with_destroy_bang
92
- # Relation.destroy!: aliased to delete
93
- ParanoidForest.rainforest.destroy!(@paranoid_forest_3)
94
- assert_equal 1, ParanoidForest.rainforest.count
95
- assert_equal 1, ParanoidForest.rainforest.with_deleted.count
96
- assert_equal 0, ParanoidForest.rainforest.only_deleted.count
97
- end
98
-
99
- def test_two_step_real_removal_through_relation_with_destroy
100
- # destroy: two-step through a relation
101
- paranoid_tree = @paranoid_forest_1.paranoid_trees.first
102
- @paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree.id)
103
- @paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree.id)
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
108
-
109
- def test_two_step_real_removal_through_relation_with_destroy_all
110
- # destroy_all: two-step through a relation
111
- @paranoid_forest_1.paranoid_trees.order(:id).destroy_all
112
- @paranoid_forest_1.paranoid_trees.only_deleted.destroy_all
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
117
-
118
- def test_real_removal_through_relation_with_delete_all_bang
119
- # delete_all!: through a relation
120
- @paranoid_forest_2.paranoid_trees.order(:id).delete_all!
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
124
- end
125
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ValidatesUniquenessTest < ParanoidBaseTest
6
- def test_should_include_deleted_by_default
7
- ParanoidTime.new(name: "paranoid").tap do |record|
8
- assert !record.valid?
9
- ParanoidTime.first.destroy
10
- assert !record.valid?
11
- ParanoidTime.only_deleted.first.destroy!
12
- assert record.valid?
13
- end
14
- end
15
-
16
- def test_should_validate_without_deleted
17
- ParanoidBoolean.new(name: "paranoid").tap do |record|
18
- refute record.valid?
19
- ParanoidBoolean.first.destroy
20
- assert record.valid?
21
- ParanoidBoolean.only_deleted.first.destroy!
22
- assert record.valid?
23
- end
24
- end
25
-
26
- def test_models_with_scoped_validations_can_be_multiply_deleted
27
- model_a = ParanoidWithScopedValidation.create(name: "Model A", category: "Category A")
28
- model_b = ParanoidWithScopedValidation.create(name: "Model B", category: "Category B")
29
-
30
- ParanoidWithScopedValidation.delete([model_a.id, model_b.id])
31
-
32
- assert_paranoid_deletion(model_a)
33
- assert_paranoid_deletion(model_b)
34
- end
35
-
36
- def test_models_with_scoped_validations_can_be_multiply_destroyed
37
- model_a = ParanoidWithScopedValidation.create(name: "Model A", category: "Category A")
38
- model_b = ParanoidWithScopedValidation.create(name: "Model B", category: "Category B")
39
-
40
- ParanoidWithScopedValidation.destroy([model_a.id, model_b.id])
41
-
42
- assert_paranoid_deletion(model_a)
43
- assert_paranoid_deletion(model_b)
44
- end
45
- end