paranoia 2.4.1 → 2.5.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: d25bfc4e0254aba4db5a58da8d666c68052e836bc2f315efbcd5ec2b77657b30
4
- data.tar.gz: d413ea576910faa0e4ebaff07c617c8692db837beeb24a5d5d43d0794170981f
3
+ metadata.gz: 3e8c766fdb37e4a9137f722b1ed77a34e7776d97c0f8a5e25f448e36c77fc332
4
+ data.tar.gz: 96087a09f51c030e0ae8c2262f0114b465aa7986231ce0ccc6458abe16b3d248
5
5
  SHA512:
6
- metadata.gz: 354429a32eb5c97b1662456e56a5df64ff8b2c0d4ae02e57d528384eb33c17a161f5972275babfd55c279f7de54552073ae425c9a2c4b676a383ca55c83a8cfe
7
- data.tar.gz: 3f5e1914d1f200e82c8e1775bf2859e253b7aa6b434eaaf841276db9f017185f0f985ff7ef80ed53d103b1f21762419315568aa097a662946aab85db28431369
6
+ metadata.gz: 3d5e2a067a77de1222ba94ebf07a6f62afc22fe4c700bbf6f5a56dbe45f0de4bde673574b0441986a2db917f8c2b592542f33cf559ba227fd6c0208dfaff9af6
7
+ data.tar.gz: 8374654630dea1028fa7b64eee00ff6abbc7ab0cbdce6b77c1fdcf34eac9aaf7df23d96f3aaa6915bf0c222169d8eccf6ec6024a0705195d43865326ece554bb
@@ -0,0 +1,61 @@
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.1
20
+ - '3.0'
21
+ - 2.7
22
+ - 2.6
23
+ - 2.5
24
+ # - jruby-9.2.19.0
25
+ # - jruby-9.3.1.0
26
+ rails:
27
+ - '~> 5.1.0'
28
+ - '~> 5.2.0'
29
+ - '~> 6.0.0'
30
+ - '~> 6.1.0'
31
+ - '~> 7.0.0'
32
+ - 'edge'
33
+ exclude:
34
+ # Rails edge is now 7.x and requires ruby 2.7
35
+ - rails: 'edge'
36
+ ruby: 2.6
37
+ - rails: 'edge'
38
+ ruby: 2.5
39
+ - rails: '~> 7.0.0'
40
+ ruby: 2.6
41
+ - rails: '~> 7.0.0'
42
+ ruby: 2.5
43
+ # Legacy Rails with newer rubies
44
+ - rails: '~> 5.1.0'
45
+ ruby: '3.0'
46
+ - rails: '~> 5.2.0'
47
+ ruby: '3.0'
48
+ - rails: '~> 5.1.0'
49
+ ruby: 3.1
50
+ - rails: '~> 5.2.0'
51
+ ruby: 3.1
52
+
53
+ env:
54
+ RAILS: ${{ matrix.rails }}
55
+ steps:
56
+ - uses: actions/checkout@v2
57
+ - uses: ruby/setup-ruby@v1
58
+ with:
59
+ ruby-version: ${{ matrix.ruby }}
60
+ bundler-cache: true
61
+ - run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,8 +1,50 @@
1
1
  # paranoia Changelog
2
2
 
3
+ ## 2.5.2
4
+
5
+ * [#492](https://github.com/rubysherpas/paranoia/pull/492) Warn if acts_as_paranoid is called more than once on the same model
6
+
7
+ [Ignatius Reza](https://github.com/ignatiusreza)
8
+
9
+ ## 2.5.1
10
+
11
+ * [#481](https://github.com/rubysherpas/paranoia/pull/481) Replaces hard coded `deleted_at` with `paranoia_column`.
12
+
13
+ [Hassanin Ahmed](https://github.com/sas1ni69)
14
+
15
+ ## 2.5.0
16
+
17
+ * [#516](https://github.com/rubysherpas/paranoia/pull/516) Add support for ActiveRecord 7.0, drop support for EOL Ruby < 2.5 and Rails < 5.1
18
+ adding support for Rails 7
19
+
20
+ [Mathieu Jobin](https://github.com/mathieujobin)
21
+ * [#515](https://github.com/rubysherpas/paranoia/pull/515) Switch from Travis CI to GitHub Actions
22
+
23
+ [Shinichi Maeshima](https://github.com/willnet)
24
+
25
+ ## 2.4.3
26
+
27
+ * [#503](https://github.com/rubysherpas/paranoia/pull/503) Bump activerecord dependency for Rails 6.1
28
+
29
+ [Jörg Schiller](https://github.com/joergschiller)
30
+
31
+ * [#483](https://github.com/rubysherpas/paranoia/pull/483) Update JRuby version to 9.2.8.0 + remove EOL Ruby 2.2
32
+
33
+ [Uwe Kubosch](https://github.com/donv)
34
+
35
+ * [#482](https://github.com/rubysherpas/paranoia/pull/482) Fix after_commit for Rails 6
36
+
37
+ [Ashwin Hegde](https://github.com/hashwin)
38
+
39
+ ## 2.4.2
40
+
41
+ * [#470](https://github.com/rubysherpas/paranoia/pull/470) Add support for ActiveRecord 6.0
42
+
43
+ [Anton Kolodii](https://github.com/iggant), [Jared Norman](https://github.com/jarednorman)
44
+
3
45
  ## 2.4.1
4
46
 
5
- * [#435](https://github.com/rubysherpas/paranoia/pull/435) Monkeypatch activerecord relations to work with rails 6.2.0
47
+ * [#435](https://github.com/rubysherpas/paranoia/pull/435) Monkeypatch activerecord relations to work with rails 5.2.0
6
48
 
7
49
  [Bartosz Bonisławski (@bbonislawski)](https://github.com/bbonislawski)
8
50
 
data/Gemfile CHANGED
@@ -1,20 +1,32 @@
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
- platforms :rbx do
10
- gem 'rubysl', '~> 2.0'
11
- gem 'rubysl-test-unit'
12
- gem 'rubinius-developer_tools'
15
+ if RUBY_ENGINE == 'rbx'
16
+ platforms :rbx do
17
+ gem 'rubinius-developer_tools'
18
+ gem 'rubysl', '~> 2.0'
19
+ gem 'rubysl-test-unit'
20
+ end
13
21
  end
14
22
 
15
23
  rails = ENV['RAILS'] || '~> 5.2.0'
16
24
 
17
- gem 'rails', rails
25
+ if rails == 'edge'
26
+ gem 'rails', github: 'rails/rails'
27
+ else
28
+ gem 'rails', rails
29
+ end
18
30
 
19
31
  # Specify your gem's dependencies in paranoia.gemspec
20
32
  gemspec
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Gem Version](https://badge.fury.io/rb/paranoia.svg)](https://badge.fury.io/rb/paranoia)
2
+ [![build](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml/badge.svg)](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml)
3
+
1
4
  **Notice:**
2
5
 
3
6
  `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.
@@ -1,23 +1,26 @@
1
- require 'rspec/expectations'
1
+ if Rails.env.test?
2
+ require 'rspec/expectations'
2
3
 
3
- # Validate the subject's class did call "acts_as_paranoid"
4
- RSpec::Matchers.define :act_as_paranoid do
5
- match { |subject| subject.class.ancestors.include?(Paranoia) }
4
+ # Validate the subject's class did call "acts_as_paranoid"
5
+ RSpec::Matchers.define :act_as_paranoid do
6
+ match { |subject| subject.class.ancestors.include?(Paranoia) }
6
7
 
7
- failure_message_proc = lambda do
8
- "expected #{subject.class} to use `acts_as_paranoid`"
9
- end
8
+ failure_message_proc = lambda do
9
+ "expected #{subject.class} to use `acts_as_paranoid`"
10
+ end
10
11
 
11
- failure_message_when_negated_proc = lambda do
12
- "expected #{subject.class} not to use `acts_as_paranoid`"
13
- end
12
+ failure_message_when_negated_proc = lambda do
13
+ "expected #{subject.class} not to use `acts_as_paranoid`"
14
+ end
14
15
 
15
- if respond_to?(:failure_message_when_negated)
16
- failure_message(&failure_message_proc)
17
- failure_message_when_negated(&failure_message_when_negated_proc)
18
- else
19
- # RSpec 2 compatibility:
20
- failure_message_for_should(&failure_message_proc)
21
- failure_message_for_should_not(&failure_message_when_negated_proc)
16
+ if respond_to?(:failure_message_when_negated)
17
+ failure_message(&failure_message_proc)
18
+ failure_message_when_negated(&failure_message_when_negated_proc)
19
+ else
20
+ # RSpec 2 compatibility:
21
+ failure_message_for_should(&failure_message_proc)
22
+ failure_message_for_should_not(&failure_message_when_negated_proc)
23
+ end
22
24
  end
23
- end
25
+
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = '2.4.1'.freeze
2
+ VERSION = '2.5.1'.freeze
3
3
  end
data/lib/paranoia.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'active_record' unless defined? ActiveRecord
2
2
 
3
- if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2]
3
+ if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] ||
4
+ ActiveRecord::VERSION::MAJOR > 5
4
5
  require 'paranoia/active_record_5_2'
5
6
  end
6
7
 
@@ -68,6 +69,7 @@ module Paranoia
68
69
  next unless send(association.reflection.name)
69
70
  association.decrement_counters
70
71
  end
72
+ @_trigger_destroy_callback = true
71
73
  @_disable_counter_cache = false
72
74
  result
73
75
  end
@@ -80,6 +82,10 @@ module Paranoia
80
82
  raise(ActiveRecord::RecordNotDestroyed.new("Failed to destroy the record", self))
81
83
  end
82
84
 
85
+ def trigger_transactional_callbacks?
86
+ super || @_trigger_destroy_callback && paranoia_destroyed?
87
+ end
88
+
83
89
  def paranoia_delete
84
90
  raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly?
85
91
  if persisted?
@@ -123,16 +129,16 @@ module Paranoia
123
129
  def get_recovery_window_range(opts)
124
130
  return opts[:recovery_window_range] if opts[:recovery_window_range]
125
131
  return unless opts[:recovery_window]
126
- (deleted_at - opts[:recovery_window]..deleted_at + opts[:recovery_window])
132
+ (deletion_time - opts[:recovery_window]..deletion_time + opts[:recovery_window])
127
133
  end
128
134
 
129
135
  def within_recovery_window?(recovery_window_range)
130
136
  return true unless recovery_window_range
131
- recovery_window_range.cover?(deleted_at)
137
+ recovery_window_range.cover?(deletion_time)
132
138
  end
133
139
 
134
140
  def paranoia_destroyed?
135
- send(paranoia_column) != paranoia_sentinel_value
141
+ deletion_time != paranoia_sentinel_value
136
142
  end
137
143
  alias :deleted? :paranoia_destroyed?
138
144
 
@@ -224,13 +230,24 @@ module Paranoia
224
230
  end
225
231
  end
226
232
 
227
- 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
228
239
  end
229
240
  end
230
241
 
231
242
  ActiveSupport.on_load(:active_record) do
232
243
  class ActiveRecord::Base
233
244
  def self.acts_as_paranoid(options={})
245
+ if included_modules.include?(Paranoia)
246
+ puts "[WARN] #{self.name} is calling acts_as_paranoid more than once!"
247
+
248
+ return
249
+ end
250
+
234
251
  define_model_callbacks :restore, :real_destroy
235
252
 
236
253
  alias_method :really_destroyed?, :destroyed?
@@ -282,6 +299,10 @@ ActiveSupport.on_load(:active_record) do
282
299
  def paranoia_sentinel_value
283
300
  self.class.paranoia_sentinel_value
284
301
  end
302
+
303
+ def deletion_time
304
+ send(paranoia_column)
305
+ end
285
306
  end
286
307
  end
287
308
 
@@ -305,12 +326,12 @@ module ActiveRecord
305
326
  class UniquenessValidator < ActiveModel::EachValidator
306
327
  prepend UniquenessParanoiaValidator
307
328
  end
308
-
329
+
309
330
  class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator
310
331
  def validate_each(record, attribute, value)
311
332
  # if association is soft destroyed, add an error
312
333
  if value.present? && value.paranoia_destroyed?
313
- record.errors[attribute] << 'has been soft-deleted'
334
+ record.errors.add(attribute, 'has been soft-deleted')
314
335
  end
315
336
  end
316
337
  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,14 +22,19 @@ 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.3'
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"
31
31
 
32
- s.files = `git ls-files`.split("\n")
32
+
33
+ s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)}) }
35
+ files
36
+ end
37
+
33
38
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
34
39
  s.require_path = 'lib'
35
40
  end
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.1
4
+ version: 2.5.1
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: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2022-02-02 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.3'
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.3'
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
@@ -87,12 +87,11 @@ files:
87
87
  - lib/paranoia/rspec.rb
88
88
  - lib/paranoia/version.rb
89
89
  - paranoia.gemspec
90
- - test/paranoia_test.rb
91
90
  homepage: https://github.com/rubysherpas/paranoia
92
91
  licenses:
93
92
  - MIT
94
93
  metadata: {}
95
- post_install_message:
94
+ post_install_message:
96
95
  rdoc_options: []
97
96
  require_paths:
98
97
  - lib
@@ -100,16 +99,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - ">="
102
101
  - !ruby/object:Gem::Version
103
- version: '2.0'
102
+ version: '2.5'
104
103
  required_rubygems_version: !ruby/object:Gem::Requirement
105
104
  requirements:
106
105
  - - ">="
107
106
  - !ruby/object:Gem::Version
108
107
  version: 1.3.6
109
108
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.7.6
112
- signing_key:
109
+ rubygems_version: 3.1.6
110
+ signing_key:
113
111
  specification_version: 4
114
112
  summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
115
113
  using much, much, much less code.
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- before_install: gem update --system
4
- cache: bundler
5
- rvm:
6
- - 2.2
7
- - 2.3.5
8
- - 2.4.3
9
- - 2.5.0
10
- - jruby-9.1.6.0
11
-
12
- env:
13
- matrix:
14
- - RAILS='~> 4.2.0'
15
- - RAILS='~> 5.0.0'
16
- - RAILS='~> 5.1.0'
17
- - RAILS='~> 5.2.0'
18
-
19
- matrix:
20
- allow_failures:
21
- - env: RAILS='~> 4.2.0'
22
- rvm: jruby-9.1.6.0
23
- - env: RAILS='~> 5.0.0'
24
- rvm: jruby-9.1.6.0
25
- - env: RAILS='~> 5.1.0'
26
- rvm: jruby-9.1.6.0
27
- - env: RAILS='~> 5.2.0'
28
- rvm: jruby-9.1.6.0