Commit 4f268326 by Ryan Bigg

really_destroy! will now really destroy dependent = :destroy associated records

Fixes #117
parent e2ef9604
......@@ -90,10 +90,15 @@ module Paranoia
# insert time to paranoia column.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions.
def touch_paranoia_column(with_transaction=false)
if with_transaction
with_transaction_returning_status { touch(paranoia_column) }
else
touch(paranoia_column)
# This method is (potentially) called from really_destroy
# The object the method is being called on may be frozen
# Let's not touch it if it's frozen.
unless self.frozen?
if with_transaction
with_transaction_returning_status { touch(paranoia_column) }
else
touch(paranoia_column)
end
end
end
......@@ -122,9 +127,20 @@ end
class ActiveRecord::Base
def self.acts_as_paranoid(options={})
alias :really_destroy! :destroy
alias :destroy! :destroy
alias :delete! :delete
def really_destroy!
dependent_reflections = self.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy
end
if dependent_reflections.any?
dependent_reflections.each do |name, _|
self.send(name).each(&:really_destroy!)
end
end
destroy!
end
include Paranoia
class_attribute :paranoia_column
......
......@@ -287,13 +287,20 @@ class ParanoiaTest < test_framework
assert model.instance_variable_get(:@restore_callback_called)
end
def test_real_destroy
def test_really_destroy
model = ParanoidModel.new
model.save
model.really_destroy!
refute ParanoidModel.unscoped.exists?(model.id)
end
def test_real_destroy_dependent_destroy
parent = ParentModel.create
child = parent.very_related_models.create
parent.really_destroy!
refute RelatedModel.unscoped.exists?(child.id)
end
if ActiveRecord::VERSION::STRING < "4.1"
def test_real_destroy
model = ParanoidModel.new
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment