Commit 29eb730f by Ryan Bigg

Revert behaviour of calling destroy twice deleting records

As per #92
parent 5efb43fe
......@@ -44,12 +44,12 @@ module Paranoia
end
def destroy
run_callbacks(:destroy) { delete_or_soft_delete(true) }
run_callbacks(:destroy) { touch_paranoia_column(true) }
end
def delete
return if new_record?
delete_or_soft_delete
touch_paranoia_column(false)
end
def restore!(opts = {})
......@@ -68,11 +68,6 @@ module Paranoia
alias :deleted? :destroyed?
private
# select and exec delete or soft-delete.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions, when soft-delete.
def delete_or_soft_delete(with_transaction=false)
destroyed? ? destroy! : touch_paranoia_column(with_transaction)
end
# touch paranoia column.
# insert time to paranoia column.
......@@ -104,8 +99,9 @@ end
class ActiveRecord::Base
def self.acts_as_paranoid(options={})
alias :destroy! :destroy
alias :delete! :delete
alias :ar_destroy :destroy
alias :destroy! :ar_destroy
alias :delete! :delete
include Paranoia
class_attribute :paranoia_column
......
......@@ -239,13 +239,14 @@ class ParanoiaTest < Test::Unit::TestCase
assert_equal false, model.destroyed?
end
# Regression test for #92
def test_destroy_twice
model = ParanoidModel.new
model.save
model.destroy
model.destroy
assert_equal 0, ParanoidModel.unscoped.where(id: model.id).count
assert_equal 1, ParanoidModel.unscoped.where(id: model.id).count
end
def test_restore_behavior_for_callbacks
......
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