diff --git a/lib/submit-request.js b/lib/submit-request.js index 5c33fb9b1..ff379801c 100644 --- a/lib/submit-request.js +++ b/lib/submit-request.js @@ -110,7 +110,7 @@ SubmitRequest.prototype.submit = function(callback) { // must get the past ops and check their src and seq values to // differentiate. request._fetchCreateOpVersion(function(error, version) { - if (err) return callback(err); + if (error) return callback(error); if (version == null) { callback(request.alreadyCreatedError()); } else { diff --git a/test/client/submit.js b/test/client/submit.js index 8f71e00ec..aa3f6850b 100644 --- a/test/client/submit.js +++ b/test/client/submit.js @@ -6,7 +6,6 @@ var deserializedType = require('./deserialized-type'); var numberType = require('./number-type'); var errorHandler = require('../util').errorHandler; var richText = require('rich-text'); -var MemoryDB = require('../../lib/db/memory'); types.register(deserializedType.type); types.register(deserializedType.type2); types.register(numberType.type); @@ -215,8 +214,8 @@ module.exports = function() { describe('no snapshot metadata available', function() { beforeEach(function() { - var getSnapshot = MemoryDB.prototype.getSnapshot; - sinon.stub(MemoryDB.prototype, 'getSnapshot') + var getSnapshot = this.backend.db.getSnapshot; + sinon.stub(this.backend.db, 'getSnapshot') .callsFake(function() { var args = Array.from(arguments); var callback = args.pop(); @@ -233,6 +232,27 @@ module.exports = function() { }); runCreateTests(); + + it('returns errors if the database cannot get committed op version', function(done) { + sinon.stub(this.backend.db, 'getCommittedOpVersion') + .callsFake(function() { + var args = Array.from(arguments); + var callback = args.pop(); + callback(new Error('uh-oh')); + }); + + var doc1 = this.backend.connect().get('dogs', 'fido'); + var doc2 = this.backend.connect().get('dogs', 'fido'); + async.series([ + doc1.create.bind(doc1, {age: 3}), + function(next) { + doc2.create({name: 'Fido'}, function(error) { + expect(error.message).to.equal('uh-oh'); + next(); + }); + } + ], done); + }); }); function runCreateTests() {