Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
don't save when destroying a non persisted object
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jan 22, 2013
1 parent 8e691b2 commit 47eda94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/acts_as_paranoid/core.rb
Expand Up @@ -106,7 +106,7 @@ def destroy
with_transaction_returning_status do
run_callbacks :destroy do
# Handle composite keys, otherwise we would just use `self.class.primary_key.to_sym => self.id`.
self.class.delete_all(Hash[[Array(self.class.primary_key), Array(self.id)].transpose])
self.class.delete_all(Hash[[Array(self.class.primary_key), Array(self.id)].transpose]) if persisted?
self.paranoid_value = self.class.delete_now_value
self
end
Expand Down
4 changes: 4 additions & 0 deletions test/test_core.rb
Expand Up @@ -63,6 +63,10 @@ def test_real_removal
assert_empty ParanoidTime.with_deleted.all
end

def test_removal_not_persisted
assert ParanoidTime.new.destroy
end

def test_recovery
assert_equal 3, ParanoidBoolean.count
ParanoidBoolean.first.destroy
Expand Down

0 comments on commit 47eda94

Please sign in to comment.