Skip to content

Commit

Permalink
Fix createIndex doesn't "do nothing" (#228)
Browse files Browse the repository at this point in the history
* Add test for broken createIndex
* Fix createIndex updating revision
  • Loading branch information
chadfawcett authored and garrensmith committed Nov 16, 2016
1 parent 1b7c92b commit e60b1e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/adapters/local/create-index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function createIndex(db, requestDef) {

viewExists = !!doc.views[viewName];

if (viewExists) {
return false;
}

doc.views[viewName] = {
map: {
fields: utils.mergeObjects(requestDef.index.fields)
Expand Down
26 changes: 26 additions & 0 deletions test/test-suite-1/test.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ module.exports = function (dbType, context) {
});
});

it('should not update an existing index', function () {
var db = context.db;
var index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
return db.createIndex(index).then(function (response) {
response.id.should.match(/^_design\//);
response.name.should.equal('foo-index');
response.result.should.equal('created');
return db.createIndex(index);
}).then(function (response) {
response.id.should.match(/^_design\//);
response.name.should.equal('foo-index');
response.result.should.equal('exists');
return response.id;
}).then(function (ddocId) {
return db.get(ddocId);
}).then(function (doc) {
doc._rev.slice(0, 1).should.equal('1');
});
});

it('throws an error for an invalid index creation', function () {
var db = context.db;
return db.createIndex('yo yo yo').then(function () {
Expand Down

0 comments on commit e60b1e5

Please sign in to comment.