From 91c6462123b1f01c57952ff1c1548081cec73d74 Mon Sep 17 00:00:00 2001 From: Eric Dobbertin Date: Mon, 14 Dec 2015 21:23:13 -0600 Subject: [PATCH] Fix bypassCollection2 inserts (closes #290) --- collection2.js | 4 ++++ tests/tests.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/collection2.js b/collection2.js index 43716a3..01672db 100644 --- a/collection2.js +++ b/collection2.js @@ -186,7 +186,11 @@ _.each(['insert', 'update'], function(methodName) { // But insert should always return an ID to match core behavior. return methodName === "insert" ? self._makeNewID() : undefined; } + } else { + // We still need to adjust args because insert does not take options + if (methodName === "insert" && typeof args[1] !== 'function') args.splice(1, 1); } + return _super.apply(self, args); }; }); diff --git a/tests/tests.js b/tests/tests.js index 0874d34..54ed440 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1036,3 +1036,24 @@ if (Meteor.isClient) { }); }); } + +// bypassCollection2 +if (Meteor.isServer) { + Tinytest.add('Collection2 - bypassCollection2', function (test) { + var id; + + try { + id = books.insert({}, {bypassCollection2: true}) + test.ok(); + } catch (error) { + test.fail(error.message); + } + + try { + books.update(id, {$set: {copies: 2}}, {bypassCollection2: true}) + test.ok(); + } catch (error) { + test.fail(error.message); + } + }); +} \ No newline at end of file