acts_as_paranoid 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0a0cec714f9701fb054580a39b677e73a3cfd3fa1909afd29dfedbbfdcb82d0
4
- data.tar.gz: bef6e1c18c141b3035d5a4b3c33cad22a398d06250f1f09730ae39662e48a0ca
3
+ metadata.gz: 6f1ac92694d6049922653950c656bbe2f9f8959045c4fb62ba212402c280f1a4
4
+ data.tar.gz: fae3cf0d15387eabc253bcaedf768f4920d49394a64eefe451e5a9adc594708d
5
5
  SHA512:
6
- metadata.gz: 804904753df983b7e366d4a6af8f4c80b24cda018a2cd2534721f7d943cc23556a9a1a9c77a7f37de335c60a3fde99639036315f235b303a60fdefc871e693b9
7
- data.tar.gz: 40e9a9229af5706aa62e319e49c74b60b2d89e8880d46f6106ec51ef44e1e4811715b514b5e691500abc65805dd521c6741130f8eba0b892d2738cfe8efca23a
6
+ metadata.gz: fe97872c256e562f77e719d7ff81f35826ed961ed4b7868950fdf04f743420012ff10d040a8b2776579733d0fc1746cafd34419fe606acdda35a41fd9917e7cf
7
+ data.tar.gz: 05c347bdd2a2f54160d8aca242a9601e328249111a01f7318fa09dfc64252bdf30dc67e875b5e928a7bada96337ad98f9ea2d2f7c77ae7d364ff6e2ad9098c74
data/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  Notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.9.0
6
+
7
+ * Support JRuby 9.4 ([#299] by [Matijs van Zuijlen][mvz])
8
+ * Add support for Ruby 3.2 ([#300] by [Matijs van Zuijlen][mvz])
9
+ * Drop support for Ruby 2.6 ([#301] by [Matijs van Zuijlen][mvz])
10
+ * Support Rails 7.1 ([#312] and [#317] by [Matijs van Zuijlen][mvz])
11
+ * Drop support for Rails 5.2 and 6.0 ([#315] by [Matijs van Zuijlen][mvz])
12
+
13
+ [#299]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/299
14
+ [#300]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/300
15
+ [#301]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/301
16
+ [#312]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/312
17
+ [#315]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/315
18
+ [#317]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/317
19
+
20
+ ## 0.8.1
21
+
22
+ * Officially support Ruby 3.1 ([#268], by [Matijs van Zuijlen][mvz])
23
+ * Fix association building for `belongs_to` with `:with_deleted` option ([#277], by [Matijs van Zuijlen][mvz])
24
+
5
25
  ## 0.8.0
6
26
 
7
27
  * Do not set `paranoid_value` when destroying fully ([#238], by [Aymeric Le Dorze][aymeric-ledorze])
@@ -134,6 +154,8 @@ Notable changes to this project will be documented in this file.
134
154
 
135
155
  <!-- issues & pull requests -->
136
156
 
157
+ [#277]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/277
158
+ [#268]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/268
137
159
  [#262]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/262
138
160
  [#261]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/261
139
161
  [#245]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/245
data/CONTRIBUTING.md CHANGED
@@ -29,7 +29,7 @@ To send pull requests or patches, please follow the instructions below.
29
29
  **If you get stuck, please make a pull request anyway and we'll try to
30
30
  help out.**
31
31
 
32
- - Make sure `rake test` runs without reporting any failures.
32
+ - Make sure `bundle exec rake` runs without reporting any failures.
33
33
  - Add tests for your feature. Otherwise, we can't see if it works or if we
34
34
  break it later.
35
35
  - Create a separate branch for your feature based off of latest master.
@@ -38,6 +38,18 @@ help out.**
38
38
  - Keep an eye on the build results in GitHub Actions. If the build fails and it
39
39
  seems due to your changes, please update your pull request with a fix.
40
40
 
41
+ ### Testing your changes
42
+
43
+ You can run the test suite with the latest version of all dependencies by running the following:
44
+
45
+ - Run `bundle install` if you haven't done so already, or `bundle update` to update the dependencies
46
+ - Run `bundle exec rake` to run the tests
47
+
48
+ To run the tests suite for a particular version of ActiveRecord use
49
+ [appraisal](https://github.com/thoughtbot/appraisal). For example, to run the
50
+ specs with ActiveRecord 6.1, run `appraisal active_record_61 rake`. See appraisal's
51
+ documentation for details.
52
+
41
53
  ### The review process
42
54
 
43
55
  - We will try to review your pull request as soon as possible but we can make no
data/README.md CHANGED
@@ -9,11 +9,10 @@ recoverable later.
9
9
 
10
10
  ## Support
11
11
 
12
- **This branch targets Rails 5.2+ and Ruby 2.5+ only**
12
+ **This version targets Rails 6.1+ and Ruby 2.7+ only**
13
13
 
14
- If you're working with Rails 5.1 and earlier, or with Ruby 2.4 or earlier,
15
- please switch to the corresponding branch or require an older version of the
16
- `acts_as_paranoid` gem.
14
+ If you're working with Rails 6.0 and earlier, or with Ruby 2.6 or earlier,
15
+ please require an older version of the `acts_as_paranoid` gem.
17
16
 
18
17
  ### Known issues
19
18
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsParanoid
4
+ # Override for ActiveRecord::Reflection::AssociationReflection
5
+ #
6
+ # This makes automatic finding of inverse associations work where the
7
+ # inverse is a belongs_to association with the :with_deleted option set.
8
+ #
9
+ # Specifying :with_deleted for the belongs_to association would stop the
10
+ # inverse from being calculated because it sets scope where there was none,
11
+ # and normally an association having a scope means ActiveRecord will not
12
+ # automatically find the inverse association.
13
+ #
14
+ # This override adds an exception to that rule only for the case where the
15
+ # scope was added just to support the :with_deleted option.
16
+ module AssociationReflection
17
+ if ActiveRecord::VERSION::MAJOR < 7
18
+ def can_find_inverse_of_automatically?(reflection)
19
+ options = reflection.options
20
+
21
+ if reflection.macro == :belongs_to && options[:with_deleted]
22
+ return false if options[:inverse_of] == false
23
+ return false if options[:foreign_key]
24
+
25
+ !options.fetch(:original_scope)
26
+ else
27
+ super
28
+ end
29
+ end
30
+ else
31
+ def scope_allows_automatic_inverse_of?(reflection, inverse_reflection)
32
+ if reflection.scope
33
+ options = reflection.options
34
+ return true if options[:with_deleted] && !options.fetch(:original_scope)
35
+ end
36
+
37
+ super
38
+ end
39
+ end
40
+ end
41
+ end
@@ -19,32 +19,45 @@ module ActsAsParanoid
19
19
 
20
20
  with_deleted = options.delete(:with_deleted)
21
21
  if with_deleted
22
- if scope
23
- old_scope = scope
24
- scope = proc do |*args|
25
- if old_scope.arity == 0
26
- instance_exec(&old_scope).with_deleted
27
- else
28
- old_scope.call(*args).with_deleted
29
- end
30
- end
31
- else
32
- scope = proc do
33
- if respond_to? :with_deleted
34
- self.with_deleted
35
- else
36
- all
37
- end
38
- end
39
- end
22
+ original_scope = scope
23
+ scope = make_scope_with_deleted(scope)
40
24
  end
41
25
 
42
26
  result = belongs_to_without_deleted(target, scope, **options)
43
27
 
44
- result.values.last.options[:with_deleted] = with_deleted if with_deleted
28
+ if with_deleted
29
+ options = result.values.last.options
30
+ options[:with_deleted] = with_deleted
31
+ options[:original_scope] = original_scope
32
+ end
45
33
 
46
34
  result
47
35
  end
36
+
37
+ private
38
+
39
+ def make_scope_with_deleted(scope)
40
+ if scope
41
+ old_scope = scope
42
+ scope = proc do |*args|
43
+ if old_scope.arity == 0
44
+ instance_exec(&old_scope).with_deleted
45
+ else
46
+ old_scope.call(*args).with_deleted
47
+ end
48
+ end
49
+ else
50
+ scope = proc do
51
+ if respond_to? :with_deleted
52
+ with_deleted
53
+ else
54
+ all
55
+ end
56
+ end
57
+ end
58
+
59
+ scope
60
+ end
48
61
  end
49
62
  end
50
63
  end
@@ -74,9 +74,11 @@ module ActsAsParanoid
74
74
  "#{table_name}.#{paranoid_column}"
75
75
  end
76
76
 
77
+ DESTROYING_ASSOCIATION_DEPENDENCY_TYPES = [:destroy, :delete_all].freeze
78
+
77
79
  def dependent_associations
78
80
  reflect_on_all_associations.select do |a|
79
- [:destroy, :delete_all].include?(a.options[:dependent])
81
+ DESTROYING_ASSOCIATION_DEPENDENCY_TYPES.include?(a.options[:dependent])
80
82
  end
81
83
  end
82
84
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsParanoid
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -5,6 +5,7 @@ require "acts_as_paranoid/core"
5
5
  require "acts_as_paranoid/associations"
6
6
  require "acts_as_paranoid/validations"
7
7
  require "acts_as_paranoid/relation"
8
+ require "acts_as_paranoid/association_reflection"
8
9
 
9
10
  module ActsAsParanoid
10
11
  def paranoid?
@@ -29,9 +30,7 @@ module ActsAsParanoid
29
30
  dependent_recovery_window: 2.minutes,
30
31
  double_tap_destroys_fully: true
31
32
  }
32
- if options[:column_type] == "string"
33
- paranoid_configuration.merge!(deleted_value: "deleted")
34
- end
33
+ paranoid_configuration[:deleted_value] = "deleted" if options[:column_type] == "string"
35
34
 
36
35
  paranoid_configuration.merge!(options) # user options
37
36
 
@@ -63,3 +62,6 @@ ActiveRecord::Relation.include ActsAsParanoid::Relation
63
62
 
64
63
  # Push the recover callback onto the activerecord callback list
65
64
  ActiveRecord::Callbacks::CALLBACKS.push(:before_recover, :after_recover)
65
+
66
+ ActiveRecord::Reflection::AssociationReflection
67
+ .prepend ActsAsParanoid::AssociationReflection
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.8.0
4
+ version: 0.9.0
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: 2021-12-17 00:00:00.000000000 Z
13
+ date: 2023-10-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,40 +18,54 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5.2'
21
+ version: '6.1'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '7.1'
24
+ version: '7.2'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '5.2'
31
+ version: '6.1'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '7.1'
34
+ version: '7.2'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activesupport
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '5.2'
41
+ version: '6.1'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '7.1'
44
+ version: '7.2'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '5.2'
51
+ version: '6.1'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '7.1'
54
+ version: '7.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 1.3.0
89
+ version: '1.3'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.3.0
96
+ version: '1.3'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -142,42 +156,84 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: 1.23.0
159
+ version: '1.52'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 1.23.0
166
+ version: '1.52'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-minitest
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: 0.17.0
173
+ version: 0.32.2
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.32.2
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-packaging
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.5.2
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.5.2
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-performance
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '1.18'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '1.18'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop-rake
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 0.6.0
160
216
  type: :development
161
217
  prerelease: false
162
218
  version_requirements: !ruby/object:Gem::Requirement
163
219
  requirements:
164
220
  - - "~>"
165
221
  - !ruby/object:Gem::Version
166
- version: 0.17.0
222
+ version: 0.6.0
167
223
  - !ruby/object:Gem::Dependency
168
224
  name: simplecov
169
225
  requirement: !ruby/object:Gem::Requirement
170
226
  requirements:
171
227
  - - "~>"
172
228
  - !ruby/object:Gem::Version
173
- version: 0.21.2
229
+ version: 0.22.0
174
230
  type: :development
175
231
  prerelease: false
176
232
  version_requirements: !ruby/object:Gem::Requirement
177
233
  requirements:
178
234
  - - "~>"
179
235
  - !ruby/object:Gem::Version
180
- version: 0.21.2
236
+ version: 0.22.0
181
237
  description: Check the home page for more in-depth information.
182
238
  email:
183
239
  - e@zzak.io
@@ -190,6 +246,7 @@ files:
190
246
  - LICENSE
191
247
  - README.md
192
248
  - lib/acts_as_paranoid.rb
249
+ - lib/acts_as_paranoid/association_reflection.rb
193
250
  - lib/acts_as_paranoid/associations.rb
194
251
  - lib/acts_as_paranoid/core.rb
195
252
  - lib/acts_as_paranoid/relation.rb
@@ -208,14 +265,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
265
  requirements:
209
266
  - - ">="
210
267
  - !ruby/object:Gem::Version
211
- version: 2.6.0
268
+ version: 2.7.0
212
269
  required_rubygems_version: !ruby/object:Gem::Requirement
213
270
  requirements:
214
271
  - - ">="
215
272
  - !ruby/object:Gem::Version
216
273
  version: '0'
217
274
  requirements: []
218
- rubygems_version: 3.2.33
275
+ rubygems_version: 3.4.20
219
276
  signing_key:
220
277
  specification_version: 4
221
278
  summary: Active Record plugin which allows you to hide and restore records without