diff --git a/lib/backend.js b/lib/backend.js index 4c1003c1..c0d4ad3f 100644 --- a/lib/backend.js +++ b/lib/backend.js @@ -391,7 +391,7 @@ Backend.prototype.fetch = function(agent, index, id, options, callback) { collection: collection, id: id }; - var snapshotOptions = options && options.snapshotOptions || {}; + var snapshotOptions = (options && options.snapshotOptions) || {}; if (agent) snapshotOptions.custom = agent.custom; backend.db.getSnapshot(collection, id, fields, snapshotOptions, function(err, snapshot) { if (err) return callback(err); @@ -439,7 +439,7 @@ Backend.prototype.fetchBulk = function(agent, index, ids, options, callback) { collection: collection, ids: ids }; - var snapshotOptions = options && options.snapshotOptions; + var snapshotOptions = (options && options.snapshotOptions) || {}; if (agent) snapshotOptions.custom = agent.custom; backend.db.getSnapshotBulk(collection, ids, fields, snapshotOptions, function(err, snapshotMap) { if (err) return callback(err); diff --git a/test/client/submit.js b/test/client/submit.js index 0db8d851..26b139aa 100644 --- a/test/client/submit.js +++ b/test/client/submit.js @@ -1,5 +1,6 @@ var async = require('async'); var expect = require('chai').expect; +var sinon = require('sinon'); var types = require('../../lib/types'); var deserializedType = require('./deserialized-type'); var numberType = require('./number-type'); @@ -44,6 +45,21 @@ module.exports = function() { }); }); + it('can create a new doc and pass options to getSnapshot', function(done) { + var connection = this.backend.connect(); + connection.agent.custom = { + foo: 'bar' + }; + var getSnapshotSpy = sinon.spy(this.backend.db, 'getSnapshot'); + connection.get('dogs', 'fido').create({age: 3}, function(err) { + if (err) return done(err); + expect(getSnapshotSpy.args[0][3]).to.deep.equal({ + custom: {foo: 'bar'} + }); + done(); + }); + }); + it('can create then delete then create a doc', function(done) { var doc = this.backend.connect().get('dogs', 'fido'); doc.create({age: 3}, function(err) {