public
Description: Rails Plugin - soft-delete your ActiveRecord records with a deleted_at timestamp. This is a much more explicit version of ActsAsParanoid
Homepage: http://6brand.com
Clone URL: git://github.com/JackDanger/permanent_records.git
Search Repo:
refactoring the permanent_records plugin.

git-svn-id: http://svn.6brand.com/projects/plugins/permanent_records@394 
7491b73d-821b-0410-9297-ad1f6b5b4194
studioda (author)
Mon Feb 18 12:54:20 -0800 2008
commit  5bd54355812c9c39bdeecfdddcdebea1be7a83d0
tree    a92af2bd7569ee3d67b28436439fa8b6899d4652
parent  fb19a7c1cc6f1a38c7a6a15cf4b8ca36768a7b19
...
50
51
52
 
 
 
 
53
54
55
56
 
 
 
57
58
59
60
61
62
63
 
 
 
64
65
66
 
67
68
69
...
50
51
52
53
54
55
56
57
58
 
 
59
60
61
62
63
64
 
 
 
 
65
66
67
68
 
69
70
71
72
73
0
@@ -50,20 +50,24 @@
0
     end
0
     
0
     def revive
0
+ set_deleted_at nil
0
+ end
0
+
0
+ def set_deleted_at(value)
0
       return self unless is_permanent?
0
       record = self.class.find(id)
0
- record.update_attribute(:deleted_at, nil)
0
- record
0
+ record.update_attribute(:deleted_at, value)
0
+ @attributes, @attributes_cache = record.attributes, record.attributes
0
+ self
0
     end
0
     
0
     def destroy_with_permanent_record(force = nil)
0
- if :force == force || !is_permanent?
0
- destroy_without_permanent_record
0
- else
0
- update_attribute(:deleted_at, Time.now)
0
+ return destroy_without_permanent_record if :force == force || !is_permanent?
0
+ unless deleted?
0
+ set_deleted_at Time.now
0
         freeze
0
- self
0
       end
0
+ self
0
     end
0
   end
0
 end
...
19
20
21
 
 
 
 
 
22
23
24
...
61
62
63
 
 
 
 
 
 
 
 
 
64
65
66
...
19
20
21
22
23
24
25
26
27
28
29
...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
0
@@ -19,6 +19,11 @@
0
   end
0
   
0
   def test_destroy_should_return_the_record
0
+ muskrat = @active
0
+ assert_equal muskrat, muskrat.destroy
0
+ end
0
+
0
+ def test_revive_should_return_the_record
0
     muskrat = @deleted
0
     assert_equal muskrat, muskrat.destroy
0
   end
0
@@ -61,6 +66,15 @@
0
   
0
   def test_deleted_returns_true_for_deleted_records
0
     assert @deleted.deleted?
0
+ end
0
+
0
+ def test_destroy_returns_record_with_modified_attributes
0
+ assert @active.destroy.deleted?
0
+ end
0
+
0
+ def test_revive_and_destroy_should_be_chainable
0
+ assert @active.destroy.revive.destroy.destroy.revive.revive.destroy.deleted?
0
+ assert !@deleted.destroy.revive.revive.destroy.destroy.revive.deleted?
0
   end
0
   
0
   def test_with_deleted_limits_scope_to_deleted_records

Comments

    No one has commented yet.