updated specs and code to reflect changes in bulk_docs for CouchDB 0.7.3

This commit is contained in:
Chris Anderson 2008-05-14 17:27:21 -07:00
parent c3b6e3e2d0
commit 81d27c6f16
3 changed files with 11 additions and 19 deletions

View file

@ -37,7 +37,7 @@ class CouchRest
end
def bulk_save docs
CouchRest.post "#{@root}/_bulk_docs", docs
CouchRest.post "#{@root}/_bulk_docs", {:docs => docs}
end
def delete doc

View file

@ -23,7 +23,7 @@ describe CouchRest do
@cr.databases.should be_an_instance_of(Array)
end
it "should get info" do
@cr.info.should == {"couchdb"=>"Welcome", "version"=>"0.0.0"}
@cr.info["couchdb"].should == "Welcome"
@cr.info.class.should == Hash
end
end

View file

@ -70,7 +70,7 @@ describe CouchRest::Database do
{"mild" => "yet local"},
{"another" => ["set","of","keys"]}
])
rs['results'].each do |r|
rs['new_revs'].each do |r|
@db.get(r['id'])
end
end
@ -80,33 +80,25 @@ describe CouchRest::Database do
{"_id" => "twoB", "mild" => "yet local"},
{"another" => ["set","of","keys"]}
])
rs['results'].each do |r|
rs['new_revs'].each do |r|
@db.get(r['id'])
end
end
it "should with one bad id should save the ones it can" do
it "in the case of an id conflict should not insert anything" do
@r = @db.save({'lemons' => 'from texas', 'and' => 'how', "_id" => "oneB"})
lambda do
rs = @db.bulk_save([
{"_id" => "oneB", "wild" => "and random"},
{"_id" => "twoB", "mild" => "yet local"},
{"another" => ["set","of","keys"]}
])
end.should raise_error(RestClient::Request::RequestFailed)
# should save the new document
newid = @db.documents['rows'].reject do |d|
['oneB','twoB'].include?(d['id'])
end.first['id']
newdoc = @db.get(newid)
newdoc["another"][2].should == 'keys'
lambda do
@db.get('twoB')
end.should raise_error(RestClient::Request::RequestFailed)
# should save the ok id
@db.get('twoB')['mild'].should == "yet local"
# should confict on the duplicate id
oneB = @db.get('oneB')
oneB['wild'].should be_nil
oneB['lemons'].should == 'from texas'
end
end