From 88caaddccbe40a148ffd83aab6fdd78b68442ecf Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Thu, 24 Jun 2010 17:56:41 +0000 Subject: don't require a revpos attribute for stubs. closes COUCHDB-809 thanks Caleb Land git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957653 13f79535-47bb-0310-9956-ffa450edef68 --- THANKS | 1 + share/www/script/test/attachments.js | 20 ++++++++++++++++++++ src/couchdb/couch_doc.erl | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/THANKS b/THANKS index 7ed26d0e..e016c467 100644 --- a/THANKS +++ b/THANKS @@ -63,5 +63,6 @@ suggesting improvements or submitting changes. Some of these people are: * Zachary Zolton * Brian Jenkins * Paul Bonser + * Caleb Land For a list of authors see the `AUTHORS` file. diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js index 36f5a5ad..322a4f50 100644 --- a/share/www/script/test/attachments.js +++ b/share/www/script/test/attachments.js @@ -244,4 +244,24 @@ couchTests.attachments= function(debug) { body: "THIS IS AN ATTACHMENT. BOOYA!" }); TEquals(400, xhr.status, "should return error code 400 Bad Request"); + + // test COUCHDB-809 - stubs should only require the 'stub' field + var bin_doc6 = { + _id: "bin_doc6", + _attachments:{ + "foo.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + } + } + } + var save_response = db.save(bin_doc6); + bin_doc6._rev = save_response["rev"]; + // stub out the attachment + bin_doc6._attachments["foo.txt"] = { stub: true }; + + var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc6", { + body: JSON.stringify(bin_doc6) + }); + TEquals(201, xhr.status, "should send 201 Created when attachment stub contains only the 'stub' field"); }; diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index 6c8f522d..0a71f2e3 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -357,9 +357,9 @@ has_stubs([_Att|Rest]) -> merge_stubs(#doc{id=Id,atts=MemBins}=StubsDoc, #doc{atts=DiskBins}) -> BinDict = dict:from_list([{Name, Att} || #att{name=Name}=Att <- DiskBins]), MergedBins = lists:map( - fun(#att{name=Name, data=stub, revpos=RevPos}) -> + fun(#att{name=Name, data=stub}) -> case dict:find(Name, BinDict) of - {ok, #att{revpos=RevPos}=DiskAtt} -> + {ok, #att{}=DiskAtt} -> DiskAtt; _ -> throw({missing_stub, -- cgit v1.2.3