acts_as_paranoid 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.1.5* (22 Sep 2005)
2
+
3
+ * Fixed bug where acts_as_paranoid would clobber other constrains
4
+ * Simplified acts_as_paranoid mixin including.
5
+
1
6
  *0.1.4* (18 Sep 2005)
2
7
 
3
8
  * First RubyForge release
data/README CHANGED
@@ -3,16 +3,24 @@
3
3
  Overrides some basic methods for the current model so that calling #destroy sets a 'deleted_at' field to the
4
4
  current timestamp. ActiveRecord is required.
5
5
 
6
- == Install
6
+ == Resources
7
7
 
8
- Gem installation:
8
+ Install
9
9
 
10
- gem install acts_as_paranoid
11
-
12
- Download:
10
+ * gem install acts_as_paranoid
13
11
 
14
- http://rubyforge.org/projects/ar-paranoid/
12
+ Rubyforge project
15
13
 
16
- == Documentation
14
+ * http://rubyforge.org/projects/ar-paranoid
17
15
 
18
- RDocs are online at http://ar-paranoid.rubyforge.org
16
+ RDocs
17
+
18
+ * http://ar-paranoid.rubyforge.org
19
+
20
+ Subversion
21
+
22
+ * http://techno-weenie.net/svn/projects/acts_as_paranoid
23
+
24
+ Collaboa
25
+
26
+ * http://collaboa.techno-weenie.net/repository/browse/acts_as_paranoid
@@ -40,15 +40,14 @@ module ActiveRecord #:nodoc:
40
40
 
41
41
  module ClassMethods
42
42
  def acts_as_paranoid
43
- return if self.included_modules.include?(ActiveRecord::Acts::Paranoid::ParanoidMethods) # don't let AR call this twice
44
- class_eval do
43
+ unless self.included_modules.include?(ActiveRecord::Acts::Paranoid::ParanoidMethods) # don't let AR call this twice
45
44
  alias_method :destroy_without_callbacks!, :destroy_without_callbacks
46
45
  class << self
47
46
  alias_method :original_find, :find
48
47
  alias_method :count_with_deleted, :count
49
48
  end
50
- include ParanoidMethods
51
49
  end
50
+ include ParanoidMethods
52
51
  end
53
52
  end
54
53
 
@@ -63,11 +62,7 @@ module ActiveRecord #:nodoc:
63
62
  call_original_find = lambda { original_find(*(args << options)) }
64
63
 
65
64
  if !options[:with_deleted]
66
- constrain = "#{table_name}.deleted_at IS NULL"
67
- constrains = (scope_constrains.nil? or scope_constrains[:conditions].nil? or scope_constrains[:conditions] == constrain) ?
68
- constrain :
69
- "#{scope_constrains[:conditions]} AND #{constrain}"
70
- constrain(:conditions => constrains) { return call_original_find.call }
65
+ constrain(scope_constrains.merge(:conditions => deleted_constrain)) { return call_original_find.call }
71
66
  end
72
67
 
73
68
  call_original_find.call
@@ -78,7 +73,14 @@ module ActiveRecord #:nodoc:
78
73
  end
79
74
 
80
75
  def count(conditions = nil, joins = nil)
81
- constrain(:conditions => "#{table_name}.deleted_at IS NULL") { count_with_deleted(conditions, joins) }
76
+ constrain(scope_constrains.merge(:conditions => deleted_constrain)) { count_with_deleted(conditions, joins) }
77
+ end
78
+
79
+ protected
80
+ def deleted_constrain
81
+ constrain = "#{table_name}.deleted_at IS NULL"
82
+ constrains = (scope_constrains.nil? or scope_constrains[:conditions].nil? or scope_constrains[:conditions] == constrain) ?
83
+ constrain : "#{scope_constrains[:conditions]} AND #{constrain}"
82
84
  end
83
85
  end
84
86
 
@@ -77,4 +77,16 @@ class ParanoidTest < Test::Unit::TestCase
77
77
  Widget.class_eval { acts_as_paranoid }
78
78
  assert Widget.find(1)
79
79
  end
80
+
81
+ def test_should_not_override_constrains_when_counting
82
+ assert_equal 1, Widget.constrain(:conditions => "title = 'widget 1'") { Widget.count }
83
+ assert_equal 0, Widget.constrain(:conditions => "title = 'deleted widget 2'") { Widget.count }
84
+ assert_equal 1, Widget.constrain(:conditions => "title = 'deleted widget 2'") { Widget.count_with_deleted }
85
+ end
86
+
87
+ def test_should_not_override_constrains_when_finding
88
+ assert_equal [1], Widget.constrain(:conditions => "title = 'widget 1'") { Widget.find(:all) }.collect { |w| w.id }
89
+ assert_equal [], Widget.constrain(:conditions => "title = 'deleted widget 2'") { Widget.find(:all) }.collect { |w| w.id }
90
+ assert_equal [2], Widget.constrain(:conditions => "title = 'deleted widget 2'") { Widget.find_with_deleted(:all) }.collect { |w| w.id }
91
+ end
80
92
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: acts_as_paranoid
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.4
7
- date: 2005-09-18
6
+ version: 0.1.5
7
+ date: 2005-09-22
8
8
  summary: acts_as_paranoid keeps models from actually being deleted by setting a deleted_at field.
9
9
  require_paths:
10
10
  - lib