Skip to content

Commit 3b17141

Browse files
committed
Fix hasWritePending in op's callback
1 parent ea5053b commit 3b17141

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/client/doc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,10 @@ Doc.prototype._hardRollback = function(err) {
888888
};
889889

890890
Doc.prototype._clearInflightOp = function(err) {
891-
var called = callEach(this.inflightOp.callbacks, err);
892-
891+
var callbacks = this.inflightOp && this.inflightOp.callbacks;
893892
this.inflightOp = null;
893+
var called = callbacks && callEach(callbacks, err);
894+
894895
this.flush();
895896
this._emitNothingPending();
896897

test/client/submit.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,39 @@ describe('client submit', function() {
10441044
});
10451045
});
10461046

1047+
it('hasWritePending is false when create\'s callback is executed', function(done) {
1048+
var doc = this.backend.connect().get('dogs', 'fido');
1049+
doc.create({age: 3}, function(err) {
1050+
if (err) return done(err);
1051+
expect(doc.hasWritePending()).equal(false);
1052+
done();
1053+
});
1054+
});
1055+
1056+
it('hasWritePending is false when submimtOp\'s callback is executed', function(done) {
1057+
var doc = this.backend.connect().get('dogs', 'fido');
1058+
doc.create({age: 3}, function(err) {
1059+
if (err) return done(err);
1060+
doc.submitOp({p: ['age'], na: 2}, function(err) {
1061+
if (err) return done(err);
1062+
expect(doc.hasWritePending()).equal(false);
1063+
done();
1064+
});
1065+
});
1066+
});
1067+
1068+
it('hasWritePending is false when del\'s callback is executed', function(done) {
1069+
var doc = this.backend.connect().get('dogs', 'fido');
1070+
doc.create({age: 3}, function(err) {
1071+
if (err) return done(err);
1072+
doc.del(function(err) {
1073+
if (err) return done(err);
1074+
expect(doc.hasWritePending()).equal(false);
1075+
done();
1076+
});
1077+
});
1078+
});
1079+
10471080
describe('type.deserialize', function() {
10481081
it('can create a new doc', function(done) {
10491082
var doc = this.backend.connect().get('dogs', 'fido');

0 commit comments

Comments
 (0)