Commit 29eb730f by Ryan Bigg

Revert behaviour of calling destroy twice deleting records

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