public
Description: ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
Clone URL: git://github.com/technoweenie/acts_as_paranoid.git
Add ParanoidFindWrapper

This module adds a wrapper around rails' find method so it would actualy 
recognize acts_as_paranoid specific options :with_deleted and 
:only_deleted.
It could be merged directly into paranoid.rb, but opted not to pollute it 
with this rather optional functionality.
oboxodo (author)
Fri Aug 29 23:18:16 -0700 2008
commit  c947a854fbb9ef00607b4a8acb236ceff1e960dd
tree    451aed1771fa60a67511461a67a13ab08f96f009
parent  b41975082dd9ed2f1e23d053c4abde25f0cda2d8
...
27
28
29
30
31
 
 
 
 
 
...
27
28
29
 
30
31
32
33
34
35
0
@@ -27,4 +27,8 @@ class << ActiveRecord::Base
0
   alias_method :has_many, :has_many_without_deleted
0
   alias_method :exists_with_deleted?, :exists?
0
 end
0
-ActiveRecord::Base.send :include, Caboose::Acts::Paranoid
0
\ No newline at end of file
0
+ActiveRecord::Base.send :include, Caboose::Acts::Paranoid
0
+ActiveRecord::Base.send :include, Caboose::Acts::ParanoidFindWrapper
0
+class << ActiveRecord::Base
0
+ alias_method_chain :acts_as_paranoid, :find_wrapper
0
+end
...
16
17
18
19
20
21
22
23
24
...
16
17
18
 
 
 
19
20
21
0
@@ -16,9 +16,6 @@ module Caboose #:nodoc:
0
     # Widget.find_with_deleted(:all)
0
     # # SELECT * FROM widgets
0
     #
0
- # Widget.find(:all, :with_deleted => true)
0
- # # SELECT * FROM widgets
0
- #
0
     # Widget.find_only_deleted(:all)
0
     # # SELECT * FROM widgets WHERE widgets.deleted_at IS NOT NULL
0
     #
...
42
43
44
 
 
 
 
 
 
 
 
 
 
45
46
47
...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -42,6 +42,16 @@ end
0
 class ParanoidTest < Test::Unit::TestCase
0
   fixtures :widgets, :categories, :categories_widgets, :tags, :taggings
0
   
0
+ def test_should_recognize_with_deleted_option
0
+ assert_equal [1, 2], Widget.find(:all, :with_deleted => true).collect { |w| w.id }
0
+ assert_equal [1], Widget.find(:all, :with_deleted => false).collect { |w| w.id }
0
+ end
0
+
0
+ def test_should_recognize_only_deleted_option
0
+ assert_equal [2], Widget.find(:all, :only_deleted => true).collect { |w| w.id }
0
+ assert_equal [1], Widget.find(:all, :only_deleted => false).collect { |w| w.id }
0
+ end
0
+
0
   def test_should_exists_with_deleted
0
     assert Widget.exists_with_deleted?(2)
0
     assert !Widget.exists?(2)

Comments

    No one has commented yet.