Created
April 10, 2014 02:56
-
-
Save nolanlawson/10339055 to your computer and use it in GitHub Desktop.
inconsistent_results_couchdb_reduce_error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should handle user errors in reduce functions', function () { | |
return new Pouch(dbName).then(function (db) { | |
function getKey(row) {return row.key; } | |
db.on('error', function () { /* noop */ }); | |
return createView(db, { | |
map : function (doc) { | |
emit(doc.name, doc.data); | |
}, | |
reduce : function (keys, values) { | |
return values[0].foo.bar; | |
} | |
}).then(function (queryFun) { | |
var docs = [ | |
{name: 'arb', _id: '0', data: {foo: {bar: 2}}}, | |
{name: 'bar', _id: '1', data: 'quux'}, | |
{name: 'bar', _id: '2', data: {foo: {bar: 1}}}, | |
{name: 'baz', _id: '3', data: 'quux'} | |
]; | |
return db.bulkDocs({docs: docs}).then(function () { | |
return db.query(queryFun, {group: true}); | |
}).then(function (res) { | |
res.rows.map(getKey).should.deep.equal(['arb', 'bar', 'bar', 'baz']); | |
return db.query(queryFun, {reduce: false}); | |
}).then(function (res) { | |
res.rows.map(getKey).should.deep.equal(['arb', 'bar', 'bar', 'baz']); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Occasionally the keys are
['arb', 'bar', 'bar', 'baz']
, occasionally they are['arb', 'bar', 'baz']
.