public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
update acts as paranoid

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1412 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sat Jul 22 18:17:17 -0700 2006
commit  77bde57a766f7091a7cc675819bab68a8312302c
tree    f8dbe3f618e1a83969a15123f31c6954bc87a6e2
parent  826ce13cd17875968bf5187ff7f38431f0b61b0d
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1 +1,16 @@
0
+class << ActiveRecord::Base
0
+ def belongs_to_with_deleted(association_id, options = {})
0
+ with_deleted = options.delete :with_deleted
0
+ returning belongs_to_without_deleted(association_id, options) do
0
+ if with_deleted
0
+ reflection = reflect_on_association(association_id)
0
+ association_accessor_methods(reflection, Caboose::Acts::BelongsToWithDeletedAssociation)
0
+ association_constructor_method(:build, reflection, Caboose::Acts::BelongsToWithDeletedAssociation)
0
+ association_constructor_method(:create, reflection, Caboose::Acts::BelongsToWithDeletedAssociation)
0
+ end
0
+ end
0
+ end
0
+
0
+ alias_method_chain :belongs_to, :deleted
0
+end
0
 ActiveRecord::Base.send :include, Caboose::Acts::Paranoid
0
\ No newline at end of file
...
53
54
55
56
57
58
59
...
85
86
87
 
 
 
 
88
89
90
...
53
54
55
 
56
57
58
...
84
85
86
87
88
89
90
91
92
93
0
@@ -53,7 +53,6 @@ module Caboose #:nodoc:
0
             alias_method :destroy_without_callbacks!, :destroy_without_callbacks
0
             class << self
0
               alias_method :find_every_with_deleted, :find_every
0
- alias_method :count_with_deleted, :count
0
               alias_method :calculate_with_deleted, :calculate
0
               alias_method :delete_all!, :delete_all
0
             end
0
@@ -85,6 +84,10 @@ module Caboose #:nodoc:
0
             end
0
           end
0
 
0
+ def count_with_deleted(*args)
0
+ calculate_with_deleted(:count, *construct_count_options_from_legacy_args(*args))
0
+ end
0
+
0
           def count(*args)
0
             with_deleted_scope { count_with_deleted(*args) }
0
           end
...
10
11
12
 
13
14
15
...
27
28
29
 
 
 
 
 
 
30
31
32
...
94
95
96
97
98
99
 
100
101
102
 
 
 
103
104
105
106
 
 
 
 
 
 
 
 
107
108
109
...
10
11
12
13
14
15
16
...
28
29
30
31
32
33
34
35
36
37
38
39
...
101
102
103
 
 
 
104
105
106
 
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
0
@@ -10,6 +10,7 @@ end
0
 
0
 class Category < ActiveRecord::Base
0
   belongs_to :widget
0
+ belongs_to :any_widget, :class_name => 'Widget', :foreign_key => 'widget_id', :with_deleted => true
0
   acts_as_paranoid
0
 
0
   def self.search(name, options = {})
0
@@ -27,6 +28,12 @@ end
0
 class ParanoidTest < Test::Unit::TestCase
0
   fixtures :widgets, :categories, :categories_widgets
0
 
0
+ def test_should_count_with_deleted
0
+ assert_equal 1, Widget.count
0
+ assert_equal 2, Widget.count_with_deleted
0
+ assert_equal 2, Widget.calculate_with_deleted(:count, :all)
0
+ end
0
+
0
   def test_should_set_deleted_at
0
     assert_equal 1, Widget.count
0
     assert_equal 1, Category.count
0
@@ -94,16 +101,24 @@ class ParanoidTest < Test::Unit::TestCase
0
     assert_equal [1, 2], Widget.find_with_deleted(:all, :order => 'id').collect { |w| w.id }
0
   end
0
   
0
- def test_should_not_find_deleted_associations
0
- assert_equal 2, Category.calculate_with_deleted(:count, :all, :conditions => 'widget_id=1')
0
-
0
+ def test_should_not_find_deleted_has_many_associations
0
     assert_equal 1, widgets(:widget_1).categories.size
0
     assert_equal [categories(:category_1)], widgets(:widget_1).categories
0
-
0
+ end
0
+
0
+ def test_should_not_find_deleted_habtm_associations
0
     assert_equal 1, widgets(:widget_1).habtm_categories.size
0
     assert_equal [categories(:category_1)], widgets(:widget_1).habtm_categories
0
   end
0
   
0
+ def test_should_not_find_deleted_belongs_to_associations
0
+ assert_nil Category.find_with_deleted(3).widget
0
+ end
0
+
0
+ def test_should_find_belongs_to_assocation_with_deleted
0
+ assert_equal Widget.find_with_deleted(2), Category.find_with_deleted(3).any_widget
0
+ end
0
+
0
   def test_should_find_first_with_deleted
0
     assert_equal widgets(:widget_1), Widget.find(:first)
0
     assert_equal 2, Widget.find_with_deleted(:first, :order => 'id desc').id

Comments

    No one has commented yet.