From 1eac462612d9d1cdcb10363f30ac2a8822bc75aa Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Fri, 5 Sep 2008 14:09:17 -0700 Subject: [PATCH] spec the error doc --- README | 1 + spec/database_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README b/README index 0af22f5..ea27ab6 100644 --- a/README +++ b/README @@ -14,6 +14,7 @@ response = @db.save({:key => 'value', 'another key' => 'another value'}) doc = @db.get(response['id']) puts doc.inspect +Please note that @cr.database('a-db-name') does not go over the wire at all. So it won't raise an error if the database does not exist. If you need to ensure that a database exists, call: @cr.create_db(dbname) rescue nilkey Bulk Save: diff --git a/spec/database_spec.rb b/spec/database_spec.rb index ed66a58..83163a5 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -137,6 +137,7 @@ describe CouchRest::Database do @db.get(r['id']) end end + it "should add them with uniq ids" do rs = @db.bulk_save([ {"_id" => "oneB", "wild" => "and random"}, @@ -147,6 +148,7 @@ describe CouchRest::Database do @db.get(r['id']) end end + it "in the case of an id conflict should not insert anything" do @r = @db.save({'lemons' => 'from texas', 'and' => 'how', "_id" => "oneB"}) @@ -159,9 +161,22 @@ describe CouchRest::Database do end.should raise_error(RestClient::RequestFailed) lambda do - @db.get('twoB') + @db.get('twoB') end.should raise_error(RestClient::ResourceNotFound) end + it "should raise an error that is useful for recovery" do + @r = @db.save({"_id" => "taken", "field" => "stuff"}) + begin + rs = @db.bulk_save([ + {"_id" => "taken", "wild" => "and random"}, + {"_id" => "free", "mild" => "yet local"}, + {"another" => ["set","of","keys"]} + ]) + rescue RestClient::RequestFailed => e + # soon CouchDB will provide _which_ docs conflicted + JSON.parse(e.response.body)['error'].should == 'conflict' + end + end end describe "POST (new document without an id)" do