paranoia 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d26c70fbc8ac814d391639ac9d6be0596c9036dd
4
- data.tar.gz: f3f88512d6c9d139577a5d7fa0038e35059b6bd9
3
+ metadata.gz: aab51c0ba1c7cc66a301e165f34ba63c47428180
4
+ data.tar.gz: 3afafc557c633dbc11e230f919c0a6f4366b5d0e
5
5
  SHA512:
6
- metadata.gz: d4bef2e4aae5e399170d62330a53303155f6e7bcb9959844dd46bdca68d0658678174c3f38abca8e0e921db4e874891c7a6f335b7d5c31af98269350d61c4a1d
7
- data.tar.gz: dc6c29b32942c270a997e266197be9c3d1a6e4d7208e6c9afb08261d258fee955ed72828495cc957129e785f5c32c82c5180ecd018fc651225ed650d5a216a2a
6
+ metadata.gz: 0e427b3d1e96e08551b0f20350dcd0f5e3739b124c8c6aba82c124055f743620bc170849525e67da16e791272ab484730a734199c358f3adac3b7ec6de0a6626
7
+ data.tar.gz: bf2c134c11990eb5766911fb6aba323fb2b35320bbc6dcdb700c45df60cc1fdea89827f3ee35fc4d120a6ef8a877792fe5b5f7ecc72852727792c4f5c493612e
@@ -2,25 +2,22 @@ sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.2.6
6
- - 2.3.3
5
+ - 2.2.7
6
+ - 2.3.4
7
7
  - 2.4.1
8
8
  - jruby-9.1.6.0
9
9
 
10
10
  env:
11
11
  matrix:
12
- - RAILS='~> 4.2.7.1'
13
- - RAILS='~> 5.0.0.1'
14
- - RAILS='~> 5.1.0.rc1'
12
+ - RAILS='~> 4.2.0'
13
+ - RAILS='~> 5.0.0'
14
+ - RAILS='~> 5.1.0'
15
15
 
16
16
  matrix:
17
- exclude:
18
- - env: RAILS='~> 5.1.0.rc1'
19
- rvm: 2.2.6
20
17
  allow_failures:
21
- - env: RAILS='~> 4.2.7.1'
18
+ - env: RAILS='~> 4.2.0'
22
19
  rvm: jruby-9.1.6.0
23
- - env: RAILS='~> 5.0.0.1'
20
+ - env: RAILS='~> 5.0.0'
24
21
  rvm: jruby-9.1.6.0
25
- - env: RAILS='~> 5.1.0.rc1'
22
+ - env: RAILS='~> 5.1.0'
26
23
  rvm: jruby-9.1.6.0
@@ -1,5 +1,19 @@
1
1
  # paranoia Changelog
2
2
 
3
+ ## 2.4.0
4
+
5
+ * [#423](https://github.com/rubysherpas/paranoia/pull/423) Add `paranoia_destroy` and `paranoia_delete` aliases
6
+
7
+ [John Hawthorn (@jhawthorn)](https://github.com/jhawthorn)
8
+
9
+ * [#408](https://github.com/rubysherpas/paranoia/pull/408) Fix instance variable `@_disable_counter_cache` not initialized warning.
10
+
11
+ [Akira Matsuda (@amatsuda)](https://github.com/amatsuda)
12
+
13
+ * [#412](https://github.com/rubysherpas/paranoia/pull/412) Fix `really_destroy!` behavior with `sentinel_value`
14
+
15
+ [Steve Rice (@steverice)](https://github.com/steverice)
16
+
3
17
  ## 2.3.1
4
18
 
5
19
  * [#397](https://github.com/rubysherpas/paranoia/pull/397) Bump active record max version to support 5.1 final
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'sqlite3', platforms: [:ruby]
4
4
 
5
5
  platforms :jruby do
6
- gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
6
+ gem 'activerecord-jdbcsqlite3-adapter'
7
7
  end
8
8
 
9
9
  platforms :rbx do
@@ -12,7 +12,7 @@ platforms :rbx do
12
12
  gem 'rubinius-developer_tools'
13
13
  end
14
14
 
15
- rails = ENV['RAILS'] || '~> 4.2.0'
15
+ rails = ENV['RAILS'] || '~> 5.1.0'
16
16
 
17
17
  gem 'rails', rails
18
18
 
@@ -14,7 +14,6 @@ module Paranoia
14
14
 
15
15
  def self.included(klazz)
16
16
  klazz.extend Query
17
- klazz.extend Callbacks
18
17
  end
19
18
 
20
19
  module Query
@@ -53,31 +52,11 @@ module Paranoia
53
52
  end
54
53
  end
55
54
 
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
55
+ def paranoia_destroy
77
56
  transaction do
78
57
  run_callbacks(:destroy) do
79
58
  @_disable_counter_cache = deleted?
80
- result = delete
59
+ result = paranoia_delete
81
60
  next result unless result && ActiveRecord::VERSION::STRING >= '4.2'
82
61
  each_counter_cached_associations do |association|
83
62
  foreign_key = association.reflection.foreign_key.to_sym
@@ -90,8 +69,14 @@ module Paranoia
90
69
  end
91
70
  end
92
71
  end
72
+ alias_method :destroy, :paranoia_destroy
93
73
 
94
- def delete
74
+ def paranoia_destroy!
75
+ paranoia_destroy ||
76
+ raise(ActiveRecord::RecordNotDestroyed.new("Failed to destroy the record", self))
77
+ end
78
+
79
+ def paranoia_delete
95
80
  raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly?
96
81
  if persisted?
97
82
  # if a transaction exists, add the record so that after_commit
@@ -103,6 +88,7 @@ module Paranoia
103
88
  end
104
89
  self
105
90
  end
91
+ alias_method :delete, :paranoia_delete
106
92
 
107
93
  def restore!(opts = {})
108
94
  self.class.transaction do
@@ -112,7 +98,7 @@ module Paranoia
112
98
  # This only happened on Rails versions earlier than 4.1.
113
99
  noop_if_frozen = ActiveRecord.version < Gem::Version.new("4.1")
114
100
  if within_recovery_window?(recovery_window_range) && ((noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen)
115
- @_disable_counter_cache = !deleted?
101
+ @_disable_counter_cache = !paranoia_destroyed?
116
102
  write_attribute paranoia_column, paranoia_sentinel_value
117
103
  update_columns(paranoia_restore_attributes)
118
104
  each_counter_cached_associations do |association|
@@ -149,7 +135,7 @@ module Paranoia
149
135
  def really_destroy!
150
136
  transaction do
151
137
  run_callbacks(:real_destroy) do
152
- @_disable_counter_cache = deleted?
138
+ @_disable_counter_cache = paranoia_destroyed?
153
139
  dependent_reflections = self.class.reflections.select do |name, reflection|
154
140
  reflection.options[:dependent] == :destroy
155
141
  end
@@ -165,7 +151,7 @@ module Paranoia
165
151
  association_data.really_destroy!
166
152
  end
167
153
  end
168
- write_attribute(paranoia_column, current_time_from_proper_timezone)
154
+ update_columns(paranoia_destroy_attributes)
169
155
  destroy_without_paranoia
170
156
  end
171
157
  end
@@ -174,7 +160,7 @@ module Paranoia
174
160
  private
175
161
 
176
162
  def each_counter_cached_associations
177
- !@_disable_counter_cache && defined?(super) ? super : []
163
+ !(defined?(@_disable_counter_cache) && @_disable_counter_cache) ? super : []
178
164
  end
179
165
 
180
166
  def paranoia_restore_attributes
@@ -241,6 +227,8 @@ end
241
227
  ActiveSupport.on_load(:active_record) do
242
228
  class ActiveRecord::Base
243
229
  def self.acts_as_paranoid(options={})
230
+ define_model_callbacks :restore, :real_destroy
231
+
244
232
  alias_method :really_destroyed?, :destroyed?
245
233
  alias_method :really_delete, :delete
246
234
  alias_method :destroy_without_paranoia, :destroy
@@ -317,7 +305,7 @@ module ActiveRecord
317
305
  class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator
318
306
  def validate_each(record, attribute, value)
319
307
  # if association is soft destroyed, add an error
320
- if value.present? && value.deleted?
308
+ if value.present? && value.paranoia_destroyed?
321
309
  record.errors[attribute] << 'has been soft-deleted'
322
310
  end
323
311
  end
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = '2.3.1'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -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
@@ -546,6 +550,14 @@ class ParanoiaTest < test_framework
546
550
  assert model.instance_variable_get(:@real_destroy_callback_called)
547
551
  end
548
552
 
553
+ def test_really_destroy_behavior_for_active_column_model
554
+ model = ActiveColumnModel.new
555
+ model.save
556
+ model.really_destroy!
557
+
558
+ refute ParanoidModel.unscoped.exists?(model.id)
559
+ end
560
+
549
561
  def test_really_delete
550
562
  model = ParanoidModel.new
551
563
  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.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - radarlistener@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord