From a4da86d013a8b98513bec11f29e4bc090cc5a3c8 Mon Sep 17 00:00:00 2001 From: Ashwin Hegde Date: Thu, 28 Nov 2019 18:58:04 +0530 Subject: [PATCH 01/15] Fix after commit for rails 6 --- lib/paranoia.rb | 1 + test/paranoia_test.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/paranoia.rb b/lib/paranoia.rb index c1b323fc..f5fda9e2 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -69,6 +69,7 @@ def paranoia_destroy next unless send(association.reflection.name) association.decrement_counters end + @_trigger_update_callback = true @_disable_counter_cache = false result end diff --git a/test/paranoia_test.rb b/test/paranoia_test.rb index e08f9a7b..84e60fcf 100644 --- a/test/paranoia_test.rb +++ b/test/paranoia_test.rb @@ -131,6 +131,21 @@ def test_destroy_behavior_for_plain_models_callbacks assert model.instance_variable_get(:@after_commit_callback_called) end + def test_destroy_behavior_for_freshly_loaded_plain_models_callbacks + model = CallbackModel.new + model.save + + model = CallbackModel.find(model.id) + model.destroy + + assert_nil model.instance_variable_get(:@update_callback_called) + assert_nil model.instance_variable_get(:@save_callback_called) + assert_nil model.instance_variable_get(:@validate_called) + + assert model.instance_variable_get(:@destroy_callback_called) + assert model.instance_variable_get(:@after_destroy_callback_called) + assert model.instance_variable_get(:@after_commit_callback_called) + end def test_delete_behavior_for_plain_models_callbacks model = CallbackModel.new From 5b6be56587389b618c76af65ed84ae46768c8f8d Mon Sep 17 00:00:00 2001 From: Ashwin Hegde Date: Thu, 28 Nov 2019 21:17:56 +0530 Subject: [PATCH 02/15] trigger_transactional_callbacks if paranoia destroyed --- lib/paranoia.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/paranoia.rb b/lib/paranoia.rb index f5fda9e2..7aac0390 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -69,7 +69,7 @@ def paranoia_destroy next unless send(association.reflection.name) association.decrement_counters end - @_trigger_update_callback = true + @_trigger_destroy_callback = true @_disable_counter_cache = false result end @@ -82,6 +82,10 @@ def paranoia_destroy! raise(ActiveRecord::RecordNotDestroyed.new("Failed to destroy the record", self)) end + def trigger_transactional_callbacks? + super || @_trigger_destroy_callback && paranoia_destroyed? + end + def paranoia_delete raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly? if persisted? From 555ce0352d538a99b9b840d2a07bf39a920d1475 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Mon, 2 Dec 2019 21:42:12 +0100 Subject: [PATCH 03/15] Update JRuby version to 9.2.8.0 + avoid gem update `gem update --system` fails with Ruby 2.2. --- .travis.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78b46b95..1f672a60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ sudo: false language: ruby -before_install: gem update --system cache: bundler rvm: - 2.2 @@ -8,7 +7,7 @@ rvm: - 2.4.5 - 2.5.3 - 2.6.3 - - jruby-9.1.6.0 + - jruby-9.2.8.0 env: matrix: @@ -21,15 +20,15 @@ env: matrix: allow_failures: - env: RAILS='~> 4.2.0' SQLITE_VERSION='~> 1.3.6' - rvm: jruby-9.1.6.0 + rvm: jruby-9.2.8.0 - env: RAILS='~> 5.0.0' SQLITE_VERSION='~> 1.3.6' - rvm: jruby-9.1.6.0 + rvm: jruby-9.2.8.0 - env: RAILS='~> 5.1.0' - rvm: jruby-9.1.6.0 + rvm: jruby-9.2.8.0 - env: RAILS='~> 5.2.0' - rvm: jruby-9.1.6.0 + rvm: jruby-9.2.8.0 - env: RAILS='master' - rvm: jruby-9.1.6.0 + rvm: jruby-9.2.8.0 exclude: - rvm: 2.2 env: RAILS='master' From d493469593b427eeccbffc234b673d2b76685e35 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Mon, 2 Dec 2019 21:56:18 +0100 Subject: [PATCH 04/15] Reinstate gem update and remove EOL Ruby 2.2 --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f672a60..93b56f50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ sudo: false language: ruby +before_install: gem update --system cache: bundler rvm: - - 2.2 - 2.3.8 - 2.4.5 - 2.5.3 @@ -30,8 +30,6 @@ matrix: - env: RAILS='master' rvm: jruby-9.2.8.0 exclude: - - rvm: 2.2 - env: RAILS='master' - rvm: 2.3.8 env: RAILS='master' - rvm: 2.4.5 From 594ec41491fa45c4eee81d56807f799f6e589144 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Mon, 2 Dec 2019 22:21:58 +0100 Subject: [PATCH 05/15] Removed extra whitespace --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 93b56f50..ee221b32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: false language: ruby -before_install: gem update --system +before_install: gem update --system cache: bundler rvm: - 2.3.8 From 41f52c3e9247c193fd0896c11b70150ee58c847a Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Mon, 2 Dec 2019 22:30:45 +0100 Subject: [PATCH 06/15] Avoid bundler 2 while testing Rails 4.2 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ee221b32..75b3a305 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ sudo: false language: ruby -before_install: gem update --system +before_install: + - gem uninstall bundler -v ">=2" + - gem install bundler -v "<2" cache: bundler rvm: - 2.3.8 From d52c66e43e2e95252d21936f52de53b3d3d1c1c5 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Mon, 2 Dec 2019 22:37:36 +0100 Subject: [PATCH 07/15] Only update bundler if necessary --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 75b3a305..764507f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ sudo: false language: ruby before_install: - - gem uninstall bundler -v ">=2" - - gem install bundler -v "<2" + - gem query -i -n "^bundler$" -v ">=2" && gem uninstall bundler -v ">=2" + - gem query -i -n "^bundler$" -v "<2" || gem install bundler -v "<2" cache: bundler rvm: - 2.3.8 From fd8264290e9b8fc5c88f9a461d96e86e590694ae Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Tue, 3 Dec 2019 09:43:48 +0100 Subject: [PATCH 08/15] Revert check for bundler >=2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 764507f6..a212bb32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: ruby before_install: - - gem query -i -n "^bundler$" -v ">=2" && gem uninstall bundler -v ">=2" + - gem query -I -n "^bundler$" -v ">=2" || gem uninstall bundler -v ">=2" - gem query -i -n "^bundler$" -v "<2" || gem install bundler -v "<2" cache: bundler rvm: From c370a188de7909d5febc271f5d709078cbe47e92 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Tue, 3 Dec 2019 10:36:14 +0100 Subject: [PATCH 09/15] Uninstall global bundler --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a212bb32..aa73c5eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: ruby before_install: - - gem query -I -n "^bundler$" -v ">=2" || gem uninstall bundler -v ">=2" + - gem query -I -n "^bundler$" -v ">=2" || gem uninstall bundler -v ">=2" || rvm @global do gem uninstall bundler -v ">=2" - gem query -i -n "^bundler$" -v "<2" || gem install bundler -v "<2" cache: bundler rvm: From 950a83fe905305a83cf39c5d813fe96796e61476 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Tue, 3 Dec 2019 11:15:14 +0100 Subject: [PATCH 10/15] Accept uninstall of executables --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aa73c5eb..8beed5a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: ruby before_install: - - gem query -I -n "^bundler$" -v ">=2" || gem uninstall bundler -v ">=2" || rvm @global do gem uninstall bundler -v ">=2" + - gem query -I -n "^bundler$" -v ">=2" || gem uninstall -x bundler -v ">=2" || rvm @global do gem uninstall -x bundler -v ">=2" - gem query -i -n "^bundler$" -v "<2" || gem install bundler -v "<2" cache: bundler rvm: From 30f82f17f6c0c01baf88e14f7aa735c284f65ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Schiller?= Date: Fri, 11 Dec 2020 22:52:23 +0100 Subject: [PATCH 11/15] Bump activerecord dependency --- .travis.yml | 7 +++++++ paranoia.gemspec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8beed5a5..abaa5b55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ env: - RAILS='~> 5.0.0' SQLITE_VERSION='~> 1.3.6' - RAILS='~> 5.1.0' - RAILS='~> 5.2.0' + - RAILS='~> 6.1.0' - RAILS='master' matrix: @@ -31,8 +32,14 @@ matrix: rvm: jruby-9.2.8.0 - env: RAILS='master' rvm: jruby-9.2.8.0 + - env: RAILS='~> 6.1.0' + rvm: jruby-9.2.8.0 exclude: - rvm: 2.3.8 env: RAILS='master' - rvm: 2.4.5 env: RAILS='master' + - rvm: 2.3.8 + env: RAILS='~> 6.1.0' + - rvm: 2.4.5 + env: RAILS='~> 6.1.0' diff --git a/paranoia.gemspec b/paranoia.gemspec index 9e401e99..6a5b4303 100644 --- a/paranoia.gemspec +++ b/paranoia.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.0' - s.add_dependency 'activerecord', '>= 4.0', '< 6.1' + s.add_dependency 'activerecord', '>= 4.0', '< 6.2' s.add_development_dependency "bundler", ">= 1.0.0" s.add_development_dependency "rake" From f504fc9ea7ea1c15142b0204fc198a3a074006aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Schiller?= Date: Fri, 11 Dec 2020 22:54:10 +0100 Subject: [PATCH 12/15] Avoid deprecated method to add error Calling `<<` to an ActiveModel::Errors message array in order to add an error is deprecated. Please call `ActiveModel::Errors#add` instead. --- lib/paranoia.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paranoia.rb b/lib/paranoia.rb index 7aac0390..13b38ab3 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -316,7 +316,7 @@ class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) # if association is soft destroyed, add an error if value.present? && value.paranoia_destroyed? - record.errors[attribute] << 'has been soft-deleted' + record.errors.add(attribute, 'has been soft-deleted') end end end From 03d0779327b1604befd6dd36001cd8fcb908bff9 Mon Sep 17 00:00:00 2001 From: Rebecca Le Date: Wed, 16 Dec 2020 15:31:01 +0800 Subject: [PATCH 13/15] Update version number --- lib/paranoia/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paranoia/version.rb b/lib/paranoia/version.rb index 046171d6..21a94bb9 100644 --- a/lib/paranoia/version.rb +++ b/lib/paranoia/version.rb @@ -1,3 +1,3 @@ module Paranoia - VERSION = '2.4.2'.freeze + VERSION = '2.4.3'.freeze end From 7c78f1f569cb779ac081eb36b156f050ff5abced Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Thu, 17 Dec 2020 17:07:24 +0900 Subject: [PATCH 14/15] Add changelog for v2.4.3 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08ac9d61..eb18fc7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # paranoia Changelog +## 2.4.3 + +* [#503](https://github.com/rubysherpas/paranoia/pull/503) Bump activerecord dependency for Rails 6.1 + + [Jörg Schiller](https://github.com/joergschiller) + +* [#483](https://github.com/rubysherpas/paranoia/pull/483) Update JRuby version to 9.2.8.0 + remove EOL Ruby 2.2 + + [Uwe Kubosch](https://github.com/donv) + +* [#482](https://github.com/rubysherpas/paranoia/pull/482) Fix after_commit for Rails 6 + + [Ashwin Hegde](https://github.com/hashwin) + ## 2.4.2 * [#470](https://github.com/rubysherpas/paranoia/pull/470) Add support for ActiveRecord 6.0 From 07a64b5a0d19e608c41dd2f6d894cc0d9fad4ed1 Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Thu, 17 Dec 2020 17:23:55 +0900 Subject: [PATCH 15/15] Update supported Rails version in paranoia.gemspec --- paranoia.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paranoia.gemspec b/paranoia.gemspec index 6a5b4303..0dc3d644 100644 --- a/paranoia.gemspec +++ b/paranoia.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.license = 'MIT' s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, using much, much, much less code." s.description = <<-DSC - Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, + Paranoia is a re-implementation of acts_as_paranoid for Rails 4, 5, and 6, using much, much, much less code. You would use either plugin / gem if you wished that when you called destroy on an Active Record object that it didn't actually destroy it, but just "hid" the record. Paranoia does this