diff --git a/CHANGELOG.md b/CHANGELOG.md index 7235478c..a8c01ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # paranoia Changelog +## 2.4.4 + +* [#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.3 * Fix deprecation message on Hash#with_indifferent_access diff --git a/lib/paranoia.rb b/lib/paranoia.rb index 707170db..4e1cc306 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -109,6 +109,7 @@ def paranoia_destroy next unless send(association.reflection.name) association.decrement_counters end + @_trigger_destroy_callback = true @_disable_counter_cache = false result end @@ -121,6 +122,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? @@ -351,7 +356,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 diff --git a/paranoia.gemspec b/paranoia.gemspec index 9e401e99..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 @@ -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" diff --git a/test/paranoia_test.rb b/test/paranoia_test.rb index 978843f3..7b4da94e 100644 --- a/test/paranoia_test.rb +++ b/test/paranoia_test.rb @@ -137,6 +137,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