diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2011-08-13 22:10:00 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2011-08-13 22:10:00 +0000 |
commit | 2eb62337efc1171d1ea1e4392f8cacf0dabc1ab0 (patch) | |
tree | 908dc32a78b1c746a97d5528101eb7979520046b /share/www | |
parent | f269c49f1d1172fc390f6d54bb79d4841f15adee (diff) |
Merge revision 1157428 from trunk
Doc validation functions from deleted ddocs must be ignored
If a design document is deleted by updating it with a "_deleted"
field set to the boolean value true, its validate_doc_update function
should be ignored for subsequent document insertions/updates.
This closes COUCHDB-1227.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1157429 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/test/design_docs.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/share/www/script/test/design_docs.js b/share/www/script/test/design_docs.js index 702f0441..dd38858a 100644 --- a/share/www/script/test/design_docs.js +++ b/share/www/script/test/design_docs.js @@ -421,6 +421,45 @@ couchTests.design_docs = function(debug) { run_on_modified_server(server_config, testFun); + // COUCHDB-1227 - if a design document is deleted, by adding a "_deleted" + // field with the boolean value true, its validate_doc_update functions + // should no longer have effect. + db.deleteDb(); + db.createDb(); + var ddoc = { + _id: "_design/test", + language: "javascript", + validate_doc_update: (function(newDoc, oldDoc, userCtx, secObj) { + if (newDoc.value % 2 == 0) { + throw({forbidden: "dont like even numbers"}); + } + return true; + }).toString() + }; + + TEquals(true, db.save(ddoc).ok); + try { + db.save({_id: "doc1", value: 4}); + T(false, "doc insertion should have failed"); + } catch (x) { + TEquals("forbidden", x.error); + } + + var doc = db.open("doc1"); + TEquals(null, doc); + ddoc._deleted = true; + TEquals(true, db.save(ddoc).ok); + + try { + TEquals(true, db.save({_id: "doc1", value: 4}).ok); + } catch (x) { + T(false, "doc insertion should have succeeded"); + } + + doc = db.open("doc1"); + TEquals(true, doc !== null, "doc was not persisted"); + TEquals(4, doc.value); + // cleanup db.deleteDb(); db2.deleteDb(); |