Permalink
Browse files

Add persisted? check to destroy!

  • Loading branch information...
1 parent 899c187 commit 734775edae2d785152ae22fff89c8deccb543afa @chuckg chuckg committed Feb 28, 2013
Showing with 13 additions and 3 deletions.
  1. +1 −1 lib/acts_as_paranoid/core.rb
  2. +12 −2 test/test_core.rb
@@ -94,7 +94,7 @@ def destroy!
run_callbacks :destroy do
destroy_dependent_associations!
# 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
freeze
end
View
@@ -68,8 +68,18 @@ def test_real_removal
assert_empty ParanoidTime.with_deleted.all
end
- def test_removal_not_persisted
- assert ParanoidTime.new.destroy
+ def test_non_persisted_destroy
+ pt = ParanoidTime.new
+ assert_nil pt.paranoid_value
+ pt.destroy
+ assert_not_nil pt.paranoid_value
+ end
+
+ def test_non_persisted_destroy!
+ pt = ParanoidTime.new
+ assert_nil pt.paranoid_value
+ pt.destroy!
+ assert_not_nil pt.paranoid_value
end
def test_recovery

0 comments on commit 734775e

Please sign in to comment.