paranoia 2.3.0 → 2.4.3

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: 3d592d028e0a4ad7c1909649973803af1ef85102
4
- data.tar.gz: a4fb1bb5daec2bd6b61c4beaa9b2ce2d415a2661
2
+ SHA256:
3
+ metadata.gz: d0174a966648c3afbf8ce8d09ef65361c48540838e705bb3327477f36ee27eff
4
+ data.tar.gz: 70a9eb72fa2cfda78c4adf5aa9918404ad5860d725ac657959f0b105fd300276
5
5
  SHA512:
6
- metadata.gz: 7a7d46b3e08208ae25969ddfe75d30ed0651ac649f834dd1ccb872197ce22ef93427281ce5c396c96d36a95f52ba53e54b81910970cedcd1ecd65d040502e819
7
- data.tar.gz: 86866ca4cfd172783fbf7c7363ece9c1aea905129e210b228a315a34f2d2d6f343d5bbdd95cf96dfd8b3aa6d6d52e5391d4c026a84434a2f53fd6d23d37db6ea
6
+ metadata.gz: 2a960433d0574c324778ae6774cc90501ee3a108c91e8aca45f91eeb59b1a80406b861b94e68b7fe391dc50c32fb7ebc034aa43296ec6ffd3bb78e863051a067
7
+ data.tar.gz: 765b1c436d256277a0ac54947584b90c69ffec5bad08011696e4a62267d1bf1e3b782957d904425933083b12e1fa3ce2668872acc83e04877304243ea96f9a61
@@ -1,26 +1,45 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ before_install:
4
+ - gem query -I -n "^bundler$" -v ">=2" || gem uninstall -x bundler -v ">=2" || rvm @global do gem uninstall -x bundler -v ">=2"
5
+ - gem query -i -n "^bundler$" -v "<2" || gem install bundler -v "<2"
3
6
  cache: bundler
4
7
  rvm:
5
- - 2.2.6
6
- - 2.3.3
7
- - 2.4.1
8
- - jruby-9.1.6.0
8
+ - 2.3.8
9
+ - 2.4.5
10
+ - 2.5.3
11
+ - 2.6.3
12
+ - jruby-9.2.8.0
9
13
 
10
14
  env:
11
15
  matrix:
12
- - RAILS='~> 4.2.7.1'
13
- - RAILS='~> 5.0.0.1'
14
- - RAILS='~> 5.1.0.rc1'
16
+ - RAILS='~> 4.2.0' SQLITE_VERSION='~> 1.3.6'
17
+ - RAILS='~> 5.0.0' SQLITE_VERSION='~> 1.3.6'
18
+ - RAILS='~> 5.1.0'
19
+ - RAILS='~> 5.2.0'
20
+ - RAILS='~> 6.1.0'
21
+ - RAILS='master'
15
22
 
16
23
  matrix:
17
- exclude:
18
- - env: RAILS='~> 5.1.0.rc1'
19
- rvm: 2.2.6
20
24
  allow_failures:
21
- - env: RAILS='~> 4.2.7.1'
22
- rvm: jruby-9.1.6.0
23
- - env: RAILS='~> 5.0.0.1'
24
- rvm: jruby-9.1.6.0
25
- - env: RAILS='~> 5.1.0.rc1'
26
- rvm: jruby-9.1.6.0
25
+ - env: RAILS='~> 4.2.0' SQLITE_VERSION='~> 1.3.6'
26
+ rvm: jruby-9.2.8.0
27
+ - env: RAILS='~> 5.0.0' SQLITE_VERSION='~> 1.3.6'
28
+ rvm: jruby-9.2.8.0
29
+ - env: RAILS='~> 5.1.0'
30
+ rvm: jruby-9.2.8.0
31
+ - env: RAILS='~> 5.2.0'
32
+ rvm: jruby-9.2.8.0
33
+ - env: RAILS='master'
34
+ rvm: jruby-9.2.8.0
35
+ - env: RAILS='~> 6.1.0'
36
+ rvm: jruby-9.2.8.0
37
+ exclude:
38
+ - rvm: 2.3.8
39
+ env: RAILS='master'
40
+ - rvm: 2.4.5
41
+ env: RAILS='master'
42
+ - rvm: 2.3.8
43
+ env: RAILS='~> 6.1.0'
44
+ - rvm: 2.4.5
45
+ env: RAILS='~> 6.1.0'
@@ -1,5 +1,35 @@
1
1
  # paranoia Changelog
2
2
 
3
+ ## 2.4.2
4
+
5
+ * [#470](https://github.com/rubysherpas/paranoia/pull/470) Add support for ActiveRecord 6.0
6
+
7
+ [Anton Kolodii](https://github.com/iggant), [Jared Norman](https://github.com/jarednorman)
8
+
9
+ ## 2.4.1
10
+
11
+ * [#435](https://github.com/rubysherpas/paranoia/pull/435) Monkeypatch activerecord relations to work with rails 5.2.0
12
+
13
+ [Bartosz Bonisławski (@bbonislawski)](https://github.com/bbonislawski)
14
+
15
+ ## 2.4.0
16
+
17
+ * [#423](https://github.com/rubysherpas/paranoia/pull/423) Add `paranoia_destroy` and `paranoia_delete` aliases
18
+
19
+ [John Hawthorn (@jhawthorn)](https://github.com/jhawthorn)
20
+
21
+ * [#408](https://github.com/rubysherpas/paranoia/pull/408) Fix instance variable `@_disable_counter_cache` not initialized warning.
22
+
23
+ [Akira Matsuda (@amatsuda)](https://github.com/amatsuda)
24
+
25
+ * [#412](https://github.com/rubysherpas/paranoia/pull/412) Fix `really_destroy!` behavior with `sentinel_value`
26
+
27
+ [Steve Rice (@steverice)](https://github.com/steverice)
28
+
29
+ ## 2.3.1
30
+
31
+ * [#397](https://github.com/rubysherpas/paranoia/pull/397) Bump active record max version to support 5.1 final
32
+
3
33
  ## 2.3.0 (2017-04-14)
4
34
 
5
35
  * [#393](https://github.com/rubysherpas/paranoia/pull/393) Drop support for Rails 4.1 and begin supporting Rails 5.1.
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
- gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
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'] || '~> 4.2.0'
21
+ rails = ENV['RAILS'] || '~> 5.2.0'
16
22
 
17
- gem 'rails', rails
23
+ if rails == 'master'
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,9 @@
1
+ **Notice:**
2
+
3
+ `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.
4
+
5
+ Paranoia will continue to accept bug fixes and support new versions of Rails but isn't accepting new features.
6
+
1
7
  # Paranoia
2
8
 
3
9
  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.
@@ -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
 
@@ -14,7 +19,6 @@ module Paranoia
14
19
 
15
20
  def self.included(klazz)
16
21
  klazz.extend Query
17
- klazz.extend Callbacks
18
22
  end
19
23
 
20
24
  module Query
@@ -53,31 +57,11 @@ module Paranoia
53
57
  end
54
58
  end
55
59
 
56
- module Callbacks
57
- def self.extended(klazz)
58
- [:restore, :real_destroy].each do |callback_name|
59
- klazz.define_callbacks callback_name
60
-
61
- klazz.define_singleton_method("before_#{callback_name}") do |*args, &block|
62
- set_callback(callback_name, :before, *args, &block)
63
- end
64
-
65
- klazz.define_singleton_method("around_#{callback_name}") do |*args, &block|
66
- set_callback(callback_name, :around, *args, &block)
67
- end
68
-
69
- klazz.define_singleton_method("after_#{callback_name}") do |*args, &block|
70
- set_callback(callback_name, :after, *args, &block)
71
- end
72
- end
73
- end
74
- end
75
-
76
- def destroy
60
+ def paranoia_destroy
77
61
  transaction do
78
62
  run_callbacks(:destroy) do
79
63
  @_disable_counter_cache = deleted?
80
- result = delete
64
+ result = paranoia_delete
81
65
  next result unless result && ActiveRecord::VERSION::STRING >= '4.2'
82
66
  each_counter_cached_associations do |association|
83
67
  foreign_key = association.reflection.foreign_key.to_sym
@@ -85,13 +69,24 @@ module Paranoia
85
69
  next unless send(association.reflection.name)
86
70
  association.decrement_counters
87
71
  end
72
+ @_trigger_destroy_callback = true
88
73
  @_disable_counter_cache = false
89
74
  result
90
75
  end
91
76
  end
92
77
  end
78
+ alias_method :destroy, :paranoia_destroy
93
79
 
94
- def delete
80
+ def paranoia_destroy!
81
+ paranoia_destroy ||
82
+ raise(ActiveRecord::RecordNotDestroyed.new("Failed to destroy the record", self))
83
+ end
84
+
85
+ def trigger_transactional_callbacks?
86
+ super || @_trigger_destroy_callback && paranoia_destroyed?
87
+ end
88
+
89
+ def paranoia_delete
95
90
  raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly?
96
91
  if persisted?
97
92
  # if a transaction exists, add the record so that after_commit
@@ -103,6 +98,7 @@ module Paranoia
103
98
  end
104
99
  self
105
100
  end
101
+ alias_method :delete, :paranoia_delete
106
102
 
107
103
  def restore!(opts = {})
108
104
  self.class.transaction do
@@ -112,7 +108,7 @@ module Paranoia
112
108
  # This only happened on Rails versions earlier than 4.1.
113
109
  noop_if_frozen = ActiveRecord.version < Gem::Version.new("4.1")
114
110
  if within_recovery_window?(recovery_window_range) && ((noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen)
115
- @_disable_counter_cache = !deleted?
111
+ @_disable_counter_cache = !paranoia_destroyed?
116
112
  write_attribute paranoia_column, paranoia_sentinel_value
117
113
  update_columns(paranoia_restore_attributes)
118
114
  each_counter_cached_associations do |association|
@@ -149,7 +145,7 @@ module Paranoia
149
145
  def really_destroy!
150
146
  transaction do
151
147
  run_callbacks(:real_destroy) do
152
- @_disable_counter_cache = deleted?
148
+ @_disable_counter_cache = paranoia_destroyed?
153
149
  dependent_reflections = self.class.reflections.select do |name, reflection|
154
150
  reflection.options[:dependent] == :destroy
155
151
  end
@@ -165,7 +161,7 @@ module Paranoia
165
161
  association_data.really_destroy!
166
162
  end
167
163
  end
168
- write_attribute(paranoia_column, current_time_from_proper_timezone)
164
+ update_columns(paranoia_destroy_attributes)
169
165
  destroy_without_paranoia
170
166
  end
171
167
  end
@@ -174,7 +170,7 @@ module Paranoia
174
170
  private
175
171
 
176
172
  def each_counter_cached_associations
177
- !@_disable_counter_cache && defined?(super) ? super : []
173
+ !(defined?(@_disable_counter_cache) && @_disable_counter_cache) ? super : []
178
174
  end
179
175
 
180
176
  def paranoia_restore_attributes
@@ -241,6 +237,8 @@ end
241
237
  ActiveSupport.on_load(:active_record) do
242
238
  class ActiveRecord::Base
243
239
  def self.acts_as_paranoid(options={})
240
+ define_model_callbacks :restore, :real_destroy
241
+
244
242
  alias_method :really_destroyed?, :destroyed?
245
243
  alias_method :really_delete, :delete
246
244
  alias_method :destroy_without_paranoia, :destroy
@@ -313,12 +311,12 @@ module ActiveRecord
313
311
  class UniquenessValidator < ActiveModel::EachValidator
314
312
  prepend UniquenessParanoiaValidator
315
313
  end
316
-
314
+
317
315
  class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator
318
316
  def validate_each(record, attribute, value)
319
317
  # if association is soft destroyed, add an error
320
- if value.present? && value.deleted?
321
- record.errors[attribute] << 'has been soft-deleted'
318
+ if value.present? && value.paranoia_destroyed?
319
+ record.errors.add(attribute, 'has been soft-deleted')
322
320
  end
323
321
  end
324
322
  end
@@ -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.3.0'.freeze
2
+ VERSION = '2.4.3'.freeze
3
3
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.required_ruby_version = '>= 2.0'
26
26
 
27
- s.add_dependency 'activerecord', '>= 4.0', '< 5.1'
27
+ s.add_dependency 'activerecord', '>= 4.0', '< 6.2'
28
28
 
29
29
  s.add_development_dependency "bundler", ">= 1.0.0"
30
30
  s.add_development_dependency "rake"
@@ -5,6 +5,10 @@ require 'paranoia'
5
5
 
6
6
  test_framework = defined?(MiniTest::Test) ? MiniTest::Test : MiniTest::Unit::TestCase
7
7
 
8
+ if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=)
9
+ ActiveRecord::Base.raise_in_transactional_callbacks = true
10
+ end
11
+
8
12
  def connect!
9
13
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', database: ':memory:'
10
14
  end
@@ -127,6 +131,21 @@ class ParanoiaTest < test_framework
127
131
  assert model.instance_variable_get(:@after_commit_callback_called)
128
132
  end
129
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
130
149
 
131
150
  def test_delete_behavior_for_plain_models_callbacks
132
151
  model = CallbackModel.new
@@ -546,6 +565,14 @@ class ParanoiaTest < test_framework
546
565
  assert model.instance_variable_get(:@real_destroy_callback_called)
547
566
  end
548
567
 
568
+ def test_really_destroy_behavior_for_active_column_model
569
+ model = ActiveColumnModel.new
570
+ model.save
571
+ model.really_destroy!
572
+
573
+ refute ParanoidModel.unscoped.exists?(model.id)
574
+ end
575
+
549
576
  def test_really_delete
550
577
  model = ParanoidModel.new
551
578
  model.save
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.3.0
4
+ version: 2.4.3
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-04-14 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.1'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.1'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -106,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
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.1.2
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.