spec the error doc

This commit is contained in:
Chris Anderson 2008-09-05 14:09:17 -07:00
parent f655284d8b
commit 1eac462612
2 changed files with 17 additions and 1 deletions

1
README
View file

@ -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:

View file

@ -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