added CR::Model#destroy
This commit is contained in:
parent
f0be835f79
commit
10806b675e
2 changed files with 31 additions and 1 deletions
|
@ -294,6 +294,15 @@ module CouchRest
|
|||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
result = database.delete self
|
||||
if result['ok']
|
||||
self['_rev'] = nil
|
||||
self['_id'] = nil
|
||||
end
|
||||
result['ok']
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def create
|
||||
|
@ -321,7 +330,7 @@ module CouchRest
|
|||
end
|
||||
|
||||
include ::Extlib::Hook
|
||||
register_instance_hooks :save, :create, :update #, :destroy
|
||||
register_instance_hooks :save, :create, :update, :destroy
|
||||
|
||||
end # class Model
|
||||
end # module CouchRest
|
|
@ -289,4 +289,25 @@ describe CouchRest::Model do
|
|||
view['rows'].find{|r|r['key'] == 'cool'}['value'].should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "destroying an instance" do
|
||||
before(:each) do
|
||||
@obj = Basic.new
|
||||
@obj.save.should == true
|
||||
end
|
||||
it "should return true" do
|
||||
result = @obj.destroy
|
||||
result.should == true
|
||||
end
|
||||
it "should be resavable" do
|
||||
@obj.destroy
|
||||
@obj.rev.should be_nil
|
||||
@obj.id.should be_nil
|
||||
@obj.save.should == true
|
||||
end
|
||||
it "should make it go away" do
|
||||
@obj.destroy
|
||||
lambda{Basic.get(@obj.id)}.should raise_error
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue