Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from tricycle/rails-6-1
Browse files Browse the repository at this point in the history
Rails 6.1
  • Loading branch information
lrworth committed Dec 21, 2020
2 parents a4f3138 + b24d966 commit 77f039c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions paranoia.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions test/paranoia_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77f039c

Please sign in to comment.