Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed with_deleted to with_destroyed. Thanks to Darcy Laycock for p…

…ointing out this inconsistancy
  • Loading branch information...
commit 8e7877ebfd83a73691470dd606e183627882ceef 1 parent 8fe83ae
Jeffrey Chupp authored
View
8 README.textile
@@ -37,10 +37,10 @@ Now our automobiles are now soft-deleteable.
that_large_automobile.destroy
Automobile.count # => 0
- Automobile.count_with_deleted # => 1
+ Automobile.count_with_destroyed # => 1
# where is that large automobile?
- that_large_automobile = Automobile.find_with_deleted(:all).first
+ that_large_automobile = Automobile.find_with_destroyed(:all).first
that_large_automobile.restore
Automobile.count # => 1
</pre>
@@ -50,10 +50,10 @@ One thing to note, destroying is always undo-able, but deleting is not.
<pre>
Automobile.destroy_all
Automobile.count # => 0
- Automobile.count_with_deleted # => 1
+ Automobile.count_with_destroyed # => 1
Automobile.delete_all
- Automobile.count_with_deleted # => 0
+ Automobile.count_with_destroyed # => 0
# And you may say to yourself, "My god! What have I done?"
</pre>
View
2  is_paranoid.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{is_paranoid}
- s.version = "0.0.1" # sigh, build the gem, github
+ s.version = "0.0.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jeffrey Chupp"]
View
8 lib/is_paranoid.rb
@@ -17,8 +17,8 @@ def is_paranoid
class_eval do
# This is the real magic. All calls made to this model will append
# the conditions deleted_at => nil. Exceptions require using
- # exclusive_scope (see self.delete_all, self.count_with_deleted,
- # and self.find_with_deleted )
+ # exclusive_scope (see self.delete_all, self.count_with_destroyed,
+ # and self.find_with_destroyed )
default_scope :conditions => {:deleted_at => nil}
# Actually delete the model, bypassing the safety net. Because
@@ -32,13 +32,13 @@ def self.delete_all conditions = nil
end
# Return a count that includes the soft-deleted models.
- def self.count_with_deleted *args
+ def self.count_with_destroyed *args
self.with_exclusive_scope { count(*args) }
end
# Return instances of all models matching the query regardless
# of whether or not they have been soft-deleted.
- def self.find_with_deleted *args
+ def self.find_with_destroyed *args
self.with_exclusive_scope { find(*args) }
end
View
16 spec/android_spec.rb
@@ -19,16 +19,16 @@ class Android < ActiveRecord::Base
end
it "should delete normally" do
- Android.count_with_deleted.should == 2
+ Android.count_with_destroyed.should == 2
Android.delete_all
- Android.count_with_deleted.should == 0
+ Android.count_with_destroyed.should == 0
end
it "should handle Model.destroy_all properly" do
lambda{
Android.destroy_all("owner_id = #{@luke.id}")
}.should change(Android, :count).from(2).to(0)
- Android.count_with_deleted.should == 2
+ Android.count_with_destroyed.should == 2
end
it "should handle Model.destroy(id) properly" do
@@ -36,7 +36,7 @@ class Android < ActiveRecord::Base
Android.destroy(@r2d2.id)
}.should change(Android, :count).from(2).to(1)
- Android.count_with_deleted.should == 2
+ Android.count_with_destroyed.should == 2
end
it "should be not show up in the relationship to the owner once deleted" do
@@ -47,24 +47,24 @@ class Android < ActiveRecord::Base
Android.first(:conditions => {:name => 'R2D2'}).should be_blank
end
- it "should be able to find deleted items via find_with_deleted" do
+ it "should be able to find deleted items via find_with_destroyed" do
@r2d2.destroy
Android.find(:first, :conditions => {:name => 'R2D2'}).should be_blank
- Android.find_with_deleted(:first, :conditions => {:name => 'R2D2'}).should_not be_blank
+ Android.find_with_destroyed(:first, :conditions => {:name => 'R2D2'}).should_not be_blank
end
it "should have a proper count inclusively and exclusively of deleted items" do
@r2d2.destroy
@c3p0.destroy
Android.count.should == 0
- Android.count_with_deleted.should == 2
+ Android.count_with_destroyed.should == 2
end
it "should mark deleted on dependent destroys" do
lambda{
@luke.destroy
}.should change(Android, :count).from(2).to(0)
- Android.count_with_deleted.should == 2
+ Android.count_with_destroyed.should == 2
end
it "should allow restoring" do
Please sign in to comment.
Something went wrong with that request. Please try again.