Skip to content

Commit

Permalink
fix argument ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindfjeldstad committed Feb 28, 2014
1 parent d99b957 commit a33c18e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ module.exports = function (a, b, filter, prefix) {
var ret = {};

if (typeof filter == 'string') {
var tmp = prefix;
prefix = filter;
filter = {};
filter = tmp;
}

if (prefix) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongo-update",
"version": "1.0.0",
"version": "1.0.1",
"description": "Diff two objects and return a MongoDB update query",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,18 @@ describe('query()', function () {
assert(!('prefix.$.b' in query.$set));
});
})

describe('when given a prefix and a filter', function () {
it('should prefix all keys in the filter', function () {
var query = diff({ a: 1, b: 2 }, { a: 2, b: 3 }, { a: 1 }, 'prefix.$');
assert(query.$set['prefix.$.a'] == 2);
assert(!('prefix.$.b' in query.$set));
});

it('should accept them in any order', function () {
var query = diff({ a: 1, b: 2 }, { a: 2, b: 3 }, 'prefix.$', { a: 1 });
assert(query.$set['prefix.$.a'] == 2);
assert(!('prefix.$.b' in query.$set));
});
})
})

0 comments on commit a33c18e

Please sign in to comment.