acts_as_paranoid 0.6.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
- require 'test_helper'
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
@@ -1,24 +1,84 @@
1
- require 'test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class RelationsTest < ActiveSupport::TestCase
6
+ class ParanoidForest < ActiveRecord::Base
7
+ acts_as_paranoid
8
+
9
+ scope :rainforest, -> { where(rainforest: true) }
10
+
11
+ has_many :paranoid_trees, dependent: :destroy
12
+ end
13
+
14
+ class ParanoidTree < ActiveRecord::Base
15
+ acts_as_paranoid
16
+ belongs_to :paranoid_forest
17
+ validates_presence_of :name
18
+ end
19
+
20
+ class NotParanoidBowl < ActiveRecord::Base
21
+ has_many :paranoid_chocolates, dependent: :destroy
22
+ end
23
+
24
+ class ParanoidChocolate < ActiveRecord::Base
25
+ acts_as_paranoid
26
+ belongs_to :not_paranoid_bowl
27
+ validates_presence_of :name
28
+ end
2
29
 
3
- class RelationsTest < ParanoidBaseTest
4
30
  def setup
5
- setup_db
31
+ ActiveRecord::Schema.define(version: 1) do
32
+ create_table :paranoid_forests do |t|
33
+ t.string :name
34
+ t.boolean :rainforest
35
+ t.datetime :deleted_at
36
+
37
+ timestamps t
38
+ end
39
+
40
+ create_table :paranoid_trees do |t|
41
+ t.integer :paranoid_forest_id
42
+ t.string :name
43
+ t.datetime :deleted_at
44
+
45
+ timestamps t
46
+ end
47
+
48
+ create_table :not_paranoid_bowls do |t|
49
+ t.string :name
50
+
51
+ timestamps t
52
+ end
6
53
 
7
- @paranoid_forest_1 = ParanoidForest.create! :name => "ParanoidForest #1"
8
- @paranoid_forest_2 = ParanoidForest.create! :name => "ParanoidForest #2", :rainforest => true
9
- @paranoid_forest_3 = ParanoidForest.create! :name => "ParanoidForest #3", :rainforest => true
54
+ create_table :paranoid_chocolates do |t|
55
+ t.integer :not_paranoid_bowl_id
56
+ t.string :name
57
+ t.datetime :deleted_at
58
+
59
+ timestamps t
60
+ end
61
+ end
62
+
63
+ @paranoid_forest_1 = ParanoidForest.create! name: "ParanoidForest #1"
64
+ @paranoid_forest_2 = ParanoidForest.create! name: "ParanoidForest #2", rainforest: true
65
+ @paranoid_forest_3 = ParanoidForest.create! name: "ParanoidForest #3", rainforest: true
10
66
 
11
67
  assert_equal 3, ParanoidForest.count
12
68
  assert_equal 2, ParanoidForest.rainforest.count
13
69
 
14
- @paranoid_forest_1.paranoid_trees.create! :name => 'ParanoidTree #1'
15
- @paranoid_forest_1.paranoid_trees.create! :name => 'ParanoidTree #2'
16
- @paranoid_forest_2.paranoid_trees.create! :name => 'ParanoidTree #3'
17
- @paranoid_forest_2.paranoid_trees.create! :name => 'ParanoidTree #4'
70
+ @paranoid_forest_1.paranoid_trees.create! name: "ParanoidTree #1"
71
+ @paranoid_forest_1.paranoid_trees.create! name: "ParanoidTree #2"
72
+ @paranoid_forest_2.paranoid_trees.create! name: "ParanoidTree #3"
73
+ @paranoid_forest_2.paranoid_trees.create! name: "ParanoidTree #4"
18
74
 
19
75
  assert_equal 4, ParanoidTree.count
20
76
  end
21
77
 
78
+ def teardown
79
+ teardown_db
80
+ end
81
+
22
82
  def test_filtering_with_scopes
23
83
  assert_equal 2, ParanoidForest.rainforest.with_deleted.count
24
84
  assert_equal 2, ParanoidForest.with_deleted.rainforest.count
@@ -81,35 +141,57 @@ class RelationsTest < ParanoidBaseTest
81
141
  assert_equal 1, ParanoidForest.rainforest.only_deleted.count
82
142
 
83
143
  # destroy_all: through a relation
84
- @paranoid_forest_2.paranoid_trees.order(:id).destroy_all
144
+ @paranoid_forest_2.paranoid_trees.destroy_all
85
145
  assert_equal 0, @paranoid_forest_2.paranoid_trees.count
86
146
  assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
87
147
  end
88
148
 
89
- def test_real_removal_through_relation
90
- # destroy!: aliased to delete
149
+ def test_fake_removal_through_has_many_relation_of_non_paranoid_model
150
+ not_paranoid = NotParanoidBowl.create! name: "NotParanoid #1"
151
+ not_paranoid.paranoid_chocolates.create! name: "ParanoidChocolate #1"
152
+ not_paranoid.paranoid_chocolates.create! name: "ParanoidChocolate #2"
153
+
154
+ not_paranoid.paranoid_chocolates.destroy_all
155
+ assert_equal 0, not_paranoid.paranoid_chocolates.count
156
+ assert_equal 2, not_paranoid.paranoid_chocolates.with_deleted.count
157
+ end
158
+
159
+ def test_real_removal_through_relation_with_destroy_fully
160
+ ParanoidForest.rainforest.destroy_fully!(@paranoid_forest_3)
161
+ assert_equal 1, ParanoidForest.rainforest.count
162
+ assert_equal 1, ParanoidForest.rainforest.with_deleted.count
163
+ assert_equal 0, ParanoidForest.rainforest.only_deleted.count
164
+ end
165
+
166
+ def test_real_removal_through_relation_with_deprecated_destroy!
91
167
  ParanoidForest.rainforest.destroy!(@paranoid_forest_3)
92
168
  assert_equal 1, ParanoidForest.rainforest.count
93
169
  assert_equal 1, ParanoidForest.rainforest.with_deleted.count
94
170
  assert_equal 0, ParanoidForest.rainforest.only_deleted.count
171
+ end
95
172
 
173
+ def test_two_step_real_removal_through_relation_with_destroy
96
174
  # destroy: two-step through a relation
97
175
  paranoid_tree = @paranoid_forest_1.paranoid_trees.first
98
- @paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree.id)
176
+ @paranoid_forest_1.paranoid_trees.destroy(paranoid_tree.id)
99
177
  @paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree.id)
100
178
  assert_equal 1, @paranoid_forest_1.paranoid_trees.count
101
179
  assert_equal 1, @paranoid_forest_1.paranoid_trees.with_deleted.count
102
180
  assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
181
+ end
103
182
 
183
+ def test_two_step_real_removal_through_relation_with_destroy_all
104
184
  # destroy_all: two-step through a relation
105
- @paranoid_forest_1.paranoid_trees.order(:id).destroy_all
185
+ @paranoid_forest_1.paranoid_trees.destroy_all
106
186
  @paranoid_forest_1.paranoid_trees.only_deleted.destroy_all
107
187
  assert_equal 0, @paranoid_forest_1.paranoid_trees.count
108
188
  assert_equal 0, @paranoid_forest_1.paranoid_trees.with_deleted.count
109
189
  assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
190
+ end
110
191
 
192
+ def test_real_removal_through_relation_with_delete_all_bang
111
193
  # delete_all!: through a relation
112
- @paranoid_forest_2.paranoid_trees.order(:id).delete_all!
194
+ @paranoid_forest_2.paranoid_trees.delete_all!
113
195
  assert_equal 0, @paranoid_forest_2.paranoid_trees.count
114
196
  assert_equal 0, @paranoid_forest_2.paranoid_trees.with_deleted.count
115
197
  assert_equal 0, @paranoid_forest_2.paranoid_trees.only_deleted.count
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class TableNamespaceTest < ActiveSupport::TestCase
6
+ module Paranoid
7
+ class Blob < ActiveRecord::Base
8
+ acts_as_paranoid
9
+
10
+ validates_presence_of :name
11
+
12
+ def self.table_name_prefix
13
+ "paranoid_"
14
+ end
15
+ end
16
+ end
17
+
18
+ def setup
19
+ ActiveRecord::Schema.define(version: 1) do
20
+ create_table :paranoid_blobs do |t|
21
+ t.string :name
22
+ t.datetime :deleted_at
23
+
24
+ timestamps t
25
+ end
26
+ end
27
+ end
28
+
29
+ def teardown
30
+ teardown_db
31
+ end
32
+
33
+ def test_correct_table_name
34
+ assert_equal "paranoid_blobs", Paranoid::Blob.table_name
35
+
36
+ b = Paranoid::Blob.new(name: "hello!")
37
+ b.save!
38
+ assert_equal b, Paranoid::Blob.first
39
+ end
40
+ end
@@ -1,8 +1,10 @@
1
- require 'test_helper'
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(:name => 'paranoid').tap do |record|
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,7 @@ class ValidatesUniquenessTest < ParanoidBaseTest
12
14
  end
13
15
 
14
16
  def test_should_validate_without_deleted
15
- ParanoidBoolean.new(:name => 'paranoid').tap do |record|
17
+ ParanoidBoolean.new(name: "paranoid").tap do |record|
16
18
  refute record.valid?
17
19
  ParanoidBoolean.first.destroy
18
20
  assert record.valid?
@@ -21,9 +23,27 @@ class ValidatesUniquenessTest < ParanoidBaseTest
21
23
  end
22
24
  end
23
25
 
26
+ def test_validate_serialized_attribute_without_deleted
27
+ ParanoidWithSerializedColumn.create!(name: "ParanoidWithSerializedColumn #1",
28
+ colors: %w[Cyan Maroon])
29
+ record = ParanoidWithSerializedColumn.new(name: "ParanoidWithSerializedColumn #2")
30
+ record.colors = %w[Cyan Maroon]
31
+ refute record.valid?
32
+
33
+ record.colors = %w[Beige Turquoise]
34
+ assert record.valid?
35
+ end
36
+
37
+ def test_updated_serialized_attribute_validated_without_deleted
38
+ record = ParanoidWithSerializedColumn.create!(name: "ParanoidWithSerializedColumn #1",
39
+ colors: %w[Cyan Maroon])
40
+ record.update!(colors: %w[Beige Turquoise])
41
+ assert record.valid?
42
+ end
43
+
24
44
  def test_models_with_scoped_validations_can_be_multiply_deleted
25
- model_a = ParanoidWithScopedValidation.create(:name => "Model A", :category => "Category A")
26
- model_b = ParanoidWithScopedValidation.create(:name => "Model B", :category => "Category B")
45
+ model_a = ParanoidWithScopedValidation.create(name: "Model A", category: "Category A")
46
+ model_b = ParanoidWithScopedValidation.create(name: "Model B", category: "Category B")
27
47
 
28
48
  ParanoidWithScopedValidation.delete([model_a.id, model_b.id])
29
49
 
@@ -32,8 +52,8 @@ class ValidatesUniquenessTest < ParanoidBaseTest
32
52
  end
33
53
 
34
54
  def test_models_with_scoped_validations_can_be_multiply_destroyed
35
- model_a = ParanoidWithScopedValidation.create(:name => "Model A", :category => "Category A")
36
- model_b = ParanoidWithScopedValidation.create(:name => "Model B", :category => "Category B")
55
+ model_a = ParanoidWithScopedValidation.create(name: "Model A", category: "Category A")
56
+ model_b = ParanoidWithScopedValidation.create(name: "Model B", category: "Category B")
37
57
 
38
58
  ParanoidWithScopedValidation.destroy([model_a.id, model_b.id])
39
59
 
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_paranoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Scott
8
8
  - Goncalo Silva
9
9
  - Rick Olson
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-10-22 00:00:00.000000000 Z
13
+ date: 2021-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '4.2'
21
+ version: '5.2'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '7.0'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '4.2'
31
+ version: '5.2'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '7.0'
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '4.2'
41
+ version: '5.2'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
44
  version: '7.0'
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '4.2'
51
+ version: '5.2'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '7.0'
@@ -73,7 +73,35 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '3.0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rake
76
+ name: minitest
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.14'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.14'
89
+ - !ruby/object:Gem::Dependency
90
+ name: minitest-focus
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.2.1
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.2.1
103
+ - !ruby/object:Gem::Dependency
104
+ name: pry
77
105
  requirement: !ruby/object:Gem::Requirement
78
106
  requirements:
79
107
  - - ">="
@@ -87,7 +115,7 @@ dependencies:
87
115
  - !ruby/object:Gem::Version
88
116
  version: '0'
89
117
  - !ruby/object:Gem::Dependency
90
- name: rdoc
118
+ name: rake
91
119
  requirement: !ruby/object:Gem::Requirement
92
120
  requirements:
93
121
  - - ">="
@@ -101,39 +129,53 @@ dependencies:
101
129
  - !ruby/object:Gem::Version
102
130
  version: '0'
103
131
  - !ruby/object:Gem::Dependency
104
- name: minitest
132
+ name: rdoc
105
133
  requirement: !ruby/object:Gem::Requirement
106
134
  requirements:
107
135
  - - ">="
108
136
  - !ruby/object:Gem::Version
109
- version: '4.0'
110
- - - "<="
111
- - !ruby/object:Gem::Version
112
- version: '6.0'
137
+ version: '0'
113
138
  type: :development
114
139
  prerelease: false
115
140
  version_requirements: !ruby/object:Gem::Requirement
116
141
  requirements:
117
142
  - - ">="
118
143
  - !ruby/object:Gem::Version
119
- version: '4.0'
120
- - - "<="
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rubocop
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 1.12.0
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
121
157
  - !ruby/object:Gem::Version
122
- version: '6.0'
158
+ version: 1.12.0
123
159
  - !ruby/object:Gem::Dependency
124
- name: pry
160
+ name: simplecov
125
161
  requirement: !ruby/object:Gem::Requirement
126
162
  requirements:
127
163
  - - ">="
128
164
  - !ruby/object:Gem::Version
129
- version: '0'
165
+ version: 0.18.1
166
+ - - "<"
167
+ - !ruby/object:Gem::Version
168
+ version: 0.22.0
130
169
  type: :development
131
170
  prerelease: false
132
171
  version_requirements: !ruby/object:Gem::Requirement
133
172
  requirements:
134
173
  - - ">="
135
174
  - !ruby/object:Gem::Version
136
- version: '0'
175
+ version: 0.18.1
176
+ - - "<"
177
+ - !ruby/object:Gem::Version
178
+ version: 0.22.0
137
179
  description: Check the home page for more in-depth information.
138
180
  email:
139
181
  - e@zzak.io
@@ -142,28 +184,30 @@ extensions: []
142
184
  extra_rdoc_files: []
143
185
  files:
144
186
  - CHANGELOG.md
187
+ - CONTRIBUTING.md
145
188
  - LICENSE
146
189
  - README.md
147
190
  - lib/acts_as_paranoid.rb
148
191
  - lib/acts_as_paranoid/associations.rb
149
192
  - lib/acts_as_paranoid/core.rb
150
- - lib/acts_as_paranoid/preloader_association.rb
151
193
  - lib/acts_as_paranoid/relation.rb
152
194
  - lib/acts_as_paranoid/validations.rb
153
195
  - lib/acts_as_paranoid/version.rb
154
196
  - test/test_associations.rb
155
197
  - test/test_core.rb
156
198
  - test/test_default_scopes.rb
199
+ - test/test_dependent_recovery.rb
200
+ - test/test_deprecated_behavior.rb
157
201
  - test/test_helper.rb
158
202
  - test/test_inheritance.rb
159
- - test/test_preloader_association.rb
160
203
  - test/test_relations.rb
204
+ - test/test_table_namespace.rb
161
205
  - test/test_validations.rb
162
206
  homepage: https://github.com/ActsAsParanoid/acts_as_paranoid
163
207
  licenses:
164
208
  - MIT
165
209
  metadata: {}
166
- post_install_message:
210
+ post_install_message:
167
211
  rdoc_options: []
168
212
  require_paths:
169
213
  - lib
@@ -171,24 +215,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
215
  requirements:
172
216
  - - ">="
173
217
  - !ruby/object:Gem::Version
174
- version: '0'
218
+ version: 2.4.0
175
219
  required_rubygems_version: !ruby/object:Gem::Requirement
176
220
  requirements:
177
221
  - - ">="
178
222
  - !ruby/object:Gem::Version
179
223
  version: '0'
180
224
  requirements: []
181
- rubygems_version: 3.0.6
182
- signing_key:
225
+ rubygems_version: 3.2.3
226
+ signing_key:
183
227
  specification_version: 4
184
228
  summary: Active Record plugin which allows you to hide and restore records without
185
229
  actually deleting them.
186
230
  test_files:
187
- - test/test_validations.rb
188
- - test/test_relations.rb
189
- - test/test_inheritance.rb
190
- - test/test_default_scopes.rb
191
231
  - test/test_associations.rb
192
- - test/test_helper.rb
193
232
  - test/test_core.rb
194
- - test/test_preloader_association.rb
233
+ - test/test_default_scopes.rb
234
+ - test/test_dependent_recovery.rb
235
+ - test/test_deprecated_behavior.rb
236
+ - test/test_helper.rb
237
+ - test/test_inheritance.rb
238
+ - test/test_relations.rb
239
+ - test/test_table_namespace.rb
240
+ - test/test_validations.rb