diff --git a/lib/database.rb b/lib/database.rb index 6629e22..4c4f80f 100644 --- a/lib/database.rb +++ b/lib/database.rb @@ -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 diff --git a/spec/couch_rest_spec.rb b/spec/couch_rest_spec.rb index f4a76b2..0a9a8c3 100644 --- a/spec/couch_rest_spec.rb +++ b/spec/couch_rest_spec.rb @@ -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 diff --git a/spec/database_spec.rb b/spec/database_spec.rb index 1f6f7bb..037f6f0 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -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"]} ]) - - # 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' + end.should raise_error(RestClient::Request::RequestFailed) + + 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