Skip to content

Commit

Permalink
fix: don't normalize options if contain key or keys property
Browse files Browse the repository at this point in the history
  • Loading branch information
ewnd9 committed Nov 4, 2016
1 parent 3b169e4 commit c226da5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Expand Up @@ -82,6 +82,10 @@ Model.prototype.findAll = function(options = {}, omitNormalization) {
* https://stackoverflow.com/questions/25728903/pouchdb-exclude-design-documents-when-using-autogenerated-uuid
*/
Model.prototype.normalizeOptions = function(options, omitDesignDocsHack) {
if (('key' in options) || ('keys' in options)) {
return options;
}

let { startkey, endkey, since, ...filteredOptions } = options;

if ('startkey' in options) {
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Expand Up @@ -116,6 +116,14 @@ test('#normalizeOptions', async t => {
endkey: '_design\uffff',
descending: true
});

t.deepEqual(model.normalizeOptions({ key: 'asd' }), {
key: 'asd'
});

t.deepEqual(model.normalizeOptions({ keys: ['asd'] }), {
keys: ['asd']
});
});

test('#findAll', async t => {
Expand Down Expand Up @@ -169,6 +177,9 @@ test('#findAll', async t => {

t.deepEqual(await fn({ since: `item:${doc3[doc3.length - 1]}`, descending: true }), [2, 1, 0]);
t.deepEqual(await fn({ since: `item:${doc3[doc3.length - 1]}`, endkey: 'item:1', descending: true }), [2, 1]);

t.deepEqual(await fn({ keys: ['item:5', 'item:7'] }), [5, 7]);
t.deepEqual(await fn({ since: `item:${doc3[doc3.length - 1]}`, keys: ['item:5', 'item:7'] }), [5, 7]); // ignore since
});

test('#findOneOrInit', async t => {
Expand Down

0 comments on commit c226da5

Please sign in to comment.