acts_as_paranoid 0.8.0 → 0.8.1

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: be004bb0de25cdda73697fa22c07d0a64e1d98c071506d4b0a608a3d3231e103
4
+ data.tar.gz: 9334fe5730d07f94d087f3e6f1d4803126224a4106cc378d9f6263fc15295d93
5
5
  SHA512:
6
- metadata.gz: 804904753df983b7e366d4a6af8f4c80b24cda018a2cd2534721f7d943cc23556a9a1a9c77a7f37de335c60a3fde99639036315f235b303a60fdefc871e693b9
7
- data.tar.gz: 40e9a9229af5706aa62e319e49c74b60b2d89e8880d46f6106ec51ef44e1e4811715b514b5e691500abc65805dd521c6741130f8eba0b892d2738cfe8efca23a
6
+ metadata.gz: c3e7ebd79d467118c9c91374088f3fe3a203ae6ca914fa036646fb77e7f4c1c9ba4e1c653dc2311ac1bd53bbf2517cb1a00ee06b32e0f09d6937bfb1ea8f6247
7
+ data.tar.gz: 99c7d3d41d9a94b26d2fed6ce5b01ea2fddfbc09bd958d9ca990a7b2d92c466a876e23011db5f7fda02b4efb9cd417b9a8dfe62a432757e788e7a89c898dbcd0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.8.1
6
+
7
+ * Officially support Ruby 3.1 ([#268], by [Matijs van Zuijlen][mvz])
8
+ * Fix association building for `belongs_to` with `:with_deleted` option ([#277], by [Matijs van Zuijlen][mvz])
9
+
5
10
  ## 0.8.0
6
11
 
7
12
  * Do not set `paranoid_value` when destroying fully ([#238], by [Aymeric Le Dorze][aymeric-ledorze])
@@ -134,6 +139,8 @@ Notable changes to this project will be documented in this file.
134
139
 
135
140
  <!-- issues & pull requests -->
136
141
 
142
+ [#277]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/277
143
+ [#268]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/268
137
144
  [#262]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/262
138
145
  [#261]: https://github.com/ActsAsParanoid/acts_as_paranoid/pull/261
139
146
  [#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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsParanoid
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.1"
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?
@@ -63,3 +64,6 @@ ActiveRecord::Relation.include ActsAsParanoid::Relation
63
64
 
64
65
  # Push the recover callback onto the activerecord callback list
65
66
  ActiveRecord::Callbacks::CALLBACKS.push(:before_recover, :after_recover)
67
+
68
+ ActiveRecord::Reflection::AssociationReflection
69
+ .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.8.1
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: 2022-04-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '7.1'
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,28 +156,28 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: 1.23.0
159
+ version: '1.25'
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.25'
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.19.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: 0.17.0
180
+ version: 0.19.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: simplecov
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +204,7 @@ files:
190
204
  - LICENSE
191
205
  - README.md
192
206
  - lib/acts_as_paranoid.rb
207
+ - lib/acts_as_paranoid/association_reflection.rb
193
208
  - lib/acts_as_paranoid/associations.rb
194
209
  - lib/acts_as_paranoid/core.rb
195
210
  - lib/acts_as_paranoid/relation.rb
@@ -215,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
230
  - !ruby/object:Gem::Version
216
231
  version: '0'
217
232
  requirements: []
218
- rubygems_version: 3.2.33
233
+ rubygems_version: 3.3.7
219
234
  signing_key:
220
235
  specification_version: 4
221
236
  summary: Active Record plugin which allows you to hide and restore records without