Skip to content

Commit

Permalink
changed with_deleted to with_destroyed. Thanks to Darcy Laycock for p…
Browse files Browse the repository at this point in the history
…ointing out this inconsistancy
  • Loading branch information
Jeffrey Chupp committed Mar 21, 2009
1 parent 8fe83ae commit 8e7877e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ Now our automobiles are now soft-deleteable.


that_large_automobile.destroy that_large_automobile.destroy
Automobile.count # => 0 Automobile.count # => 0
Automobile.count_with_deleted # => 1 Automobile.count_with_destroyed # => 1


# where is that large automobile? # 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 that_large_automobile.restore
Automobile.count # => 1 Automobile.count # => 1
</pre> </pre>
Expand All @@ -50,10 +50,10 @@ One thing to note, destroying is always undo-able, but deleting is not.
<pre> <pre>
Automobile.destroy_all Automobile.destroy_all
Automobile.count # => 0 Automobile.count # => 0
Automobile.count_with_deleted # => 1 Automobile.count_with_destroyed # => 1


Automobile.delete_all 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?" # And you may say to yourself, "My god! What have I done?"
</pre> </pre>


Expand Down
2 changes: 1 addition & 1 deletion is_paranoid.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{is_paranoid} 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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jeffrey Chupp"] s.authors = ["Jeffrey Chupp"]
Expand Down
8 changes: 4 additions & 4 deletions lib/is_paranoid.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def is_paranoid
class_eval do class_eval do
# This is the real magic. All calls made to this model will append # This is the real magic. All calls made to this model will append
# the conditions deleted_at => nil. Exceptions require using # the conditions deleted_at => nil. Exceptions require using
# exclusive_scope (see self.delete_all, self.count_with_deleted, # exclusive_scope (see self.delete_all, self.count_with_destroyed,
# and self.find_with_deleted ) # and self.find_with_destroyed )
default_scope :conditions => {:deleted_at => nil} default_scope :conditions => {:deleted_at => nil}


# Actually delete the model, bypassing the safety net. Because # Actually delete the model, bypassing the safety net. Because
Expand All @@ -32,13 +32,13 @@ def self.delete_all conditions = nil
end end


# Return a count that includes the soft-deleted models. # 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) } self.with_exclusive_scope { count(*args) }
end end


# Return instances of all models matching the query regardless # Return instances of all models matching the query regardless
# of whether or not they have been soft-deleted. # 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) } self.with_exclusive_scope { find(*args) }
end end


Expand Down
16 changes: 8 additions & 8 deletions spec/android_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ class Android < ActiveRecord::Base
end end


it "should delete normally" do it "should delete normally" do
Android.count_with_deleted.should == 2 Android.count_with_destroyed.should == 2
Android.delete_all Android.delete_all
Android.count_with_deleted.should == 0 Android.count_with_destroyed.should == 0
end end


it "should handle Model.destroy_all properly" do it "should handle Model.destroy_all properly" do
lambda{ lambda{
Android.destroy_all("owner_id = #{@luke.id}") Android.destroy_all("owner_id = #{@luke.id}")
}.should change(Android, :count).from(2).to(0) }.should change(Android, :count).from(2).to(0)
Android.count_with_deleted.should == 2 Android.count_with_destroyed.should == 2
end end


it "should handle Model.destroy(id) properly" do it "should handle Model.destroy(id) properly" do
lambda{ lambda{
Android.destroy(@r2d2.id) Android.destroy(@r2d2.id)
}.should change(Android, :count).from(2).to(1) }.should change(Android, :count).from(2).to(1)


Android.count_with_deleted.should == 2 Android.count_with_destroyed.should == 2
end end


it "should be not show up in the relationship to the owner once deleted" do it "should be not show up in the relationship to the owner once deleted" do
Expand All @@ -47,24 +47,24 @@ class Android < ActiveRecord::Base
Android.first(:conditions => {:name => 'R2D2'}).should be_blank Android.first(:conditions => {:name => 'R2D2'}).should be_blank
end 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 @r2d2.destroy
Android.find(:first, :conditions => {:name => 'R2D2'}).should be_blank 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 end


it "should have a proper count inclusively and exclusively of deleted items" do it "should have a proper count inclusively and exclusively of deleted items" do
@r2d2.destroy @r2d2.destroy
@c3p0.destroy @c3p0.destroy
Android.count.should == 0 Android.count.should == 0
Android.count_with_deleted.should == 2 Android.count_with_destroyed.should == 2
end end


it "should mark deleted on dependent destroys" do it "should mark deleted on dependent destroys" do
lambda{ lambda{
@luke.destroy @luke.destroy
}.should change(Android, :count).from(2).to(0) }.should change(Android, :count).from(2).to(0)
Android.count_with_deleted.should == 2 Android.count_with_destroyed.should == 2
end end


it "should allow restoring" do it "should allow restoring" do
Expand Down

0 comments on commit 8e7877e

Please sign in to comment.