paranoia 2.4.0 → 2.5.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
- SHA1:
3
- metadata.gz: aab51c0ba1c7cc66a301e165f34ba63c47428180
4
- data.tar.gz: 3afafc557c633dbc11e230f919c0a6f4366b5d0e
2
+ SHA256:
3
+ metadata.gz: 722efe26008fec67396f31b78997d981323a85ded9232369e36b06f9c6a2c254
4
+ data.tar.gz: 4262aeee60d6beb99958ffe43032f47cab4b9ce556663daf7c6d9b34c9a17d7e
5
5
  SHA512:
6
- metadata.gz: 0e427b3d1e96e08551b0f20350dcd0f5e3739b124c8c6aba82c124055f743620bc170849525e67da16e791272ab484730a734199c358f3adac3b7ec6de0a6626
7
- data.tar.gz: bf2c134c11990eb5766911fb6aba323fb2b35320bbc6dcdb700c45df60cc1fdea89827f3ee35fc4d120a6ef8a877792fe5b5f7ecc72852727792c4f5c493612e
6
+ metadata.gz: 1e39832dc8d08052777e4c750a6481d4eb2280823561d2adfc6844426b7a23caf79eeb97fc9d98931da5f30142af0b241f6e3cc920ff82362bd5a605abc1b1f3
7
+ data.tar.gz: 684e92dc3ff1a24cd965ae4d03ef43b22e6ccc3c6a8cf73b41062d50d98568b1393ddfcc54a3f9e5630f65eba474b87ab202e03c9ca3613f82b470e434c5d12c
@@ -0,0 +1,56 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-20.04
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby:
19
+ # - 3.0 # incompatible with rubysl
20
+ - 2.7
21
+ - 2.6
22
+ - 2.5
23
+ # - jruby-9.2.19.0
24
+ # - jruby-9.3.1.0
25
+ rails:
26
+ - '~> 5.1.0'
27
+ - '~> 5.2.0'
28
+ - '~> 6.0.0'
29
+ - '~> 6.1.0'
30
+ - '~> 7.0.0'
31
+ - 'edge'
32
+ exclude:
33
+ # Rails edge is now 7.x and requires ruby 2.7
34
+ - rails: 'edge'
35
+ ruby: 2.6
36
+ - rails: 'edge'
37
+ ruby: 2.5
38
+ - rails: '~> 7.0.0'
39
+ ruby: 2.6
40
+ - rails: '~> 7.0.0'
41
+ ruby: 2.5
42
+ # Legacy Rails with newer rubies
43
+ - rails: '~> 5.1.0'
44
+ ruby: 3.0
45
+ - rails: '~> 5.2.0'
46
+ ruby: 3.0
47
+
48
+ env:
49
+ RAILS: ${{ matrix.rails }}
50
+ steps:
51
+ - uses: actions/checkout@v2
52
+ - uses: ruby/setup-ruby@v1
53
+ with:
54
+ ruby-version: ${{ matrix.ruby }}
55
+ bundler-cache: true
56
+ - run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # paranoia Changelog
2
2
 
3
+ ## 2.4.3
4
+
5
+ * [#503](https://github.com/rubysherpas/paranoia/pull/503) Bump activerecord dependency for Rails 6.1
6
+
7
+ [Jörg Schiller](https://github.com/joergschiller)
8
+
9
+ * [#483](https://github.com/rubysherpas/paranoia/pull/483) Update JRuby version to 9.2.8.0 + remove EOL Ruby 2.2
10
+
11
+ [Uwe Kubosch](https://github.com/donv)
12
+
13
+ * [#482](https://github.com/rubysherpas/paranoia/pull/482) Fix after_commit for Rails 6
14
+
15
+ [Ashwin Hegde](https://github.com/hashwin)
16
+
17
+ ## 2.4.2
18
+
19
+ * [#470](https://github.com/rubysherpas/paranoia/pull/470) Add support for ActiveRecord 6.0
20
+
21
+ [Anton Kolodii](https://github.com/iggant), [Jared Norman](https://github.com/jarednorman)
22
+
23
+ ## 2.4.1
24
+
25
+ * [#435](https://github.com/rubysherpas/paranoia/pull/435) Monkeypatch activerecord relations to work with rails 5.2.0
26
+
27
+ [Bartosz Bonisławski (@bbonislawski)](https://github.com/bbonislawski)
28
+
3
29
  ## 2.4.0
4
30
 
5
31
  * [#423](https://github.com/rubysherpas/paranoia/pull/423) Add `paranoia_destroy` and `paranoia_delete` aliases
data/Gemfile CHANGED
@@ -1,20 +1,30 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platforms: [:ruby]
3
+ sqlite = ENV['SQLITE_VERSION']
4
+
5
+ if sqlite
6
+ gem 'sqlite3', sqlite, platforms: [:ruby]
7
+ else
8
+ gem 'sqlite3', platforms: [:ruby]
9
+ end
4
10
 
5
11
  platforms :jruby do
6
12
  gem 'activerecord-jdbcsqlite3-adapter'
7
13
  end
8
14
 
9
15
  platforms :rbx do
16
+ gem 'rubinius-developer_tools'
10
17
  gem 'rubysl', '~> 2.0'
11
18
  gem 'rubysl-test-unit'
12
- gem 'rubinius-developer_tools'
13
19
  end
14
20
 
15
- rails = ENV['RAILS'] || '~> 5.1.0'
21
+ rails = ENV['RAILS'] || '~> 5.2.0'
16
22
 
17
- gem 'rails', rails
23
+ if rails == 'edge'
24
+ gem 'rails', github: 'rails/rails'
25
+ else
26
+ gem 'rails', rails
27
+ end
18
28
 
19
29
  # Specify your gem's dependencies in paranoia.gemspec
20
30
  gemspec
data/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ [![Gem Version](https://badge.fury.io/rb/paranoia.svg)](https://badge.fury.io/rb/paranoia)
2
+
3
+ **Notice:**
4
+
5
+ `paranoia` has some surprising behaviour (like overriding ActiveRecord's `delete` and `destroy`) and is not recommended for new projects. See [`discard`'s README](https://github.com/jhawthorn/discard#why-not-paranoia-or-acts_as_paranoid) for more details.
6
+
7
+ Paranoia will continue to accept bug fixes and support new versions of Rails but isn't accepting new features.
8
+
1
9
  # Paranoia
2
10
 
3
11
  Paranoia is a re-implementation of [acts\_as\_paranoid](http://github.com/ActsAsParanoid/acts_as_paranoid) for Rails 3/4/5, using much, much, much less code.
@@ -0,0 +1,41 @@
1
+ module HandleParanoiaDestroyedInBelongsToAssociation
2
+ def handle_dependency
3
+ return unless load_target
4
+
5
+ case options[:dependent]
6
+ when :destroy
7
+ target.destroy
8
+ if target.respond_to?(:paranoia_destroyed?)
9
+ raise ActiveRecord::Rollback unless target.paranoia_destroyed?
10
+ else
11
+ raise ActiveRecord::Rollback unless target.destroyed?
12
+ end
13
+ else
14
+ target.send(options[:dependent])
15
+ end
16
+ end
17
+ end
18
+
19
+ module HandleParanoiaDestroyedInHasOneAssociation
20
+ def delete(method = options[:dependent])
21
+ if load_target
22
+ case method
23
+ when :delete
24
+ target.delete
25
+ when :destroy
26
+ target.destroyed_by_association = reflection
27
+ target.destroy
28
+ if target.respond_to?(:paranoia_destroyed?)
29
+ throw(:abort) unless target.paranoia_destroyed?
30
+ else
31
+ throw(:abort) unless target.destroyed?
32
+ end
33
+ when :nullify
34
+ target.update_columns(reflection.foreign_key => nil) if target.persisted?
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ ActiveRecord::Associations::BelongsToAssociation.prepend HandleParanoiaDestroyedInBelongsToAssociation
41
+ ActiveRecord::Associations::HasOneAssociation.prepend HandleParanoiaDestroyedInHasOneAssociation
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = '2.4.0'.freeze
2
+ VERSION = '2.5.0'.freeze
3
3
  end
data/lib/paranoia.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'active_record' unless defined? ActiveRecord
2
2
 
3
+ if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] ||
4
+ ActiveRecord::VERSION::MAJOR > 5
5
+ require 'paranoia/active_record_5_2'
6
+ end
7
+
3
8
  module Paranoia
4
9
  @@default_sentinel_value = nil
5
10
 
@@ -64,6 +69,7 @@ module Paranoia
64
69
  next unless send(association.reflection.name)
65
70
  association.decrement_counters
66
71
  end
72
+ @_trigger_destroy_callback = true
67
73
  @_disable_counter_cache = false
68
74
  result
69
75
  end
@@ -76,6 +82,10 @@ module Paranoia
76
82
  raise(ActiveRecord::RecordNotDestroyed.new("Failed to destroy the record", self))
77
83
  end
78
84
 
85
+ def trigger_transactional_callbacks?
86
+ super || @_trigger_destroy_callback && paranoia_destroyed?
87
+ end
88
+
79
89
  def paranoia_delete
80
90
  raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly?
81
91
  if persisted?
@@ -220,7 +230,12 @@ module Paranoia
220
230
  end
221
231
  end
222
232
 
223
- clear_association_cache if destroyed_associations.present?
233
+ if ActiveRecord.version.to_s > '7'
234
+ # Method deleted in https://github.com/rails/rails/commit/dd5886d00a2d5f31ccf504c391aad93deb014eb8
235
+ @association_cache.clear if persisted? && destroyed_associations.present?
236
+ else
237
+ clear_association_cache if destroyed_associations.present?
238
+ end
224
239
  end
225
240
  end
226
241
 
@@ -301,12 +316,12 @@ module ActiveRecord
301
316
  class UniquenessValidator < ActiveModel::EachValidator
302
317
  prepend UniquenessParanoiaValidator
303
318
  end
304
-
319
+
305
320
  class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator
306
321
  def validate_each(record, attribute, value)
307
322
  # if association is soft destroyed, add an error
308
323
  if value.present? && value.paranoia_destroyed?
309
- record.errors[attribute] << 'has been soft-deleted'
324
+ record.errors.add(attribute, 'has been soft-deleted')
310
325
  end
311
326
  end
312
327
  end
data/paranoia.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.license = 'MIT'
12
12
  s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, using much, much, much less code."
13
13
  s.description = <<-DSC
14
- Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
14
+ Paranoia is a re-implementation of acts_as_paranoid for Rails 4, 5, 6, and 7,
15
15
  using much, much, much less code. You would use either plugin / gem if you
16
16
  wished that when you called destroy on an Active Record object that it
17
17
  didn't actually destroy it, but just "hid" the record. Paranoia does this
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.required_rubygems_version = ">= 1.3.6"
24
24
 
25
- s.required_ruby_version = '>= 2.0'
25
+ s.required_ruby_version = '>= 2.5'
26
26
 
27
- s.add_dependency 'activerecord', '>= 4.0', '< 5.2'
27
+ s.add_dependency 'activerecord', '>= 5.1', '< 7.1'
28
28
 
29
29
  s.add_development_dependency "bundler", ">= 1.0.0"
30
30
  s.add_development_dependency "rake"
@@ -131,6 +131,21 @@ class ParanoiaTest < test_framework
131
131
  assert model.instance_variable_get(:@after_commit_callback_called)
132
132
  end
133
133
 
134
+ def test_destroy_behavior_for_freshly_loaded_plain_models_callbacks
135
+ model = CallbackModel.new
136
+ model.save
137
+
138
+ model = CallbackModel.find(model.id)
139
+ model.destroy
140
+
141
+ assert_nil model.instance_variable_get(:@update_callback_called)
142
+ assert_nil model.instance_variable_get(:@save_callback_called)
143
+ assert_nil model.instance_variable_get(:@validate_called)
144
+
145
+ assert model.instance_variable_get(:@destroy_callback_called)
146
+ assert model.instance_variable_get(:@after_destroy_callback_called)
147
+ assert model.instance_variable_get(:@after_commit_callback_called)
148
+ end
134
149
 
135
150
  def test_delete_behavior_for_plain_models_callbacks
136
151
  model = CallbackModel.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - radarlistener@gmail.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2021-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.0'
29
+ version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  description: |2
62
- Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
62
+ Paranoia is a re-implementation of acts_as_paranoid for Rails 4, 5, 6, and 7,
63
63
  using much, much, much less code. You would use either plugin / gem if you
64
64
  wished that when you called destroy on an Active Record object that it
65
65
  didn't actually destroy it, but just "hid" the record. Paranoia does this
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/build.yml"
76
77
  - ".gitignore"
77
- - ".travis.yml"
78
78
  - CHANGELOG.md
79
79
  - CODE_OF_CONDUCT.md
80
80
  - CONTRIBUTING.md
@@ -83,6 +83,7 @@ files:
83
83
  - README.md
84
84
  - Rakefile
85
85
  - lib/paranoia.rb
86
+ - lib/paranoia/active_record_5_2.rb
86
87
  - lib/paranoia/rspec.rb
87
88
  - lib/paranoia/version.rb
88
89
  - paranoia.gemspec
@@ -91,7 +92,7 @@ homepage: https://github.com/rubysherpas/paranoia
91
92
  licenses:
92
93
  - MIT
93
94
  metadata: {}
94
- post_install_message:
95
+ post_install_message:
95
96
  rdoc_options: []
96
97
  require_paths:
97
98
  - lib
@@ -99,16 +100,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
100
  requirements:
100
101
  - - ">="
101
102
  - !ruby/object:Gem::Version
102
- version: '2.0'
103
+ version: '2.5'
103
104
  required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  requirements:
105
106
  - - ">="
106
107
  - !ruby/object:Gem::Version
107
108
  version: 1.3.6
108
109
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.6.11
111
- signing_key:
110
+ rubygems_version: 3.2.11
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
114
114
  using much, much, much less code.
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.2.7
6
- - 2.3.4
7
- - 2.4.1
8
- - jruby-9.1.6.0
9
-
10
- env:
11
- matrix:
12
- - RAILS='~> 4.2.0'
13
- - RAILS='~> 5.0.0'
14
- - RAILS='~> 5.1.0'
15
-
16
- matrix:
17
- allow_failures:
18
- - env: RAILS='~> 4.2.0'
19
- rvm: jruby-9.1.6.0
20
- - env: RAILS='~> 5.0.0'
21
- rvm: jruby-9.1.6.0
22
- - env: RAILS='~> 5.1.0'
23
- rvm: jruby-9.1.6.0