diff --git a/.gitignore b/.gitignore index 28a59dc..f3ba0ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules npm-debug.log test/fixtures/README.md -test/fixtures/not-found.txt \ No newline at end of file +test/fixtures/not-found.txt +.idea \ No newline at end of file diff --git a/lib/cradle/database/documents.js b/lib/cradle/database/documents.js index d01ffe0..0491d1a 100644 --- a/lib/cradle/database/documents.js +++ b/lib/cradle/database/documents.js @@ -95,7 +95,6 @@ Database.prototype.save = function (/* [id], [rev], doc | [doc, ...] */) { Database.prototype._save = function (id, rev, doc, callback) { var options = this.connection.options; var document = {}, that = this; - // Bulk Insert if (Array.isArray(doc)) { document.docs = doc; @@ -113,9 +112,13 @@ Database.prototype._save = function (id, rev, doc, callback) { // PUT a single document, with an id (Create or Update) if (id) { // Design document - if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc)) { - document.language = "javascript"; - document.views = doc; + if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc) ) { + if( !doc.indexes ){ + document.language = "javascript"; + document.views = doc; + } else { + document.indexes = doc.indexes + } } else { document = doc; } diff --git a/test/database-test.js b/test/database-test.js index 64cf135..6b5a99d 100644 --- a/test/database-test.js +++ b/test/database-test.js @@ -71,6 +71,22 @@ function shouldQueryCouch(name) { }, "creates a new document (201)": macros.status(201) }, + "with indexes as root node" : { + topic: function (db) { + db.save('_design/search_couch_lucene', { + indexes: { + search_name:{ + index: function(doc){index('default', doc.name); + } + } + } + }, this.callback); + }, + "creates a new document (201)": macros.status(201), + "returns the revision": function (res) { + assert.ok(res.rev); + } + }, "with a '_design' id": { topic: function (db) { db.save('_design/horses', {