Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/client/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,14 @@ Doc.prototype.ingestSnapshot = function(snapshot, callback) {
};

Doc.prototype.whenNothingPending = function(callback) {
if (this.hasPending()) {
this.once('nothing pending', callback);
return;
}
callback();
var doc = this;
process.nextTick(function() {
if (doc.hasPending()) {
doc.once('nothing pending', callback);
return;
}
callback();
});
};

Doc.prototype.hasPending = function() {
Expand Down
41 changes: 26 additions & 15 deletions test/client/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,39 @@ describe('Doc', function() {
expect(doc).equal(doc2);
});

it('calling doc.destroy unregisters it', function() {
var doc = this.connection.get('dogs', 'fido');
expect(this.connection.getExisting('dogs', 'fido')).equal(doc);
it('calling doc.destroy unregisters it', function(done) {
var connection = this.connection;
var doc = connection.get('dogs', 'fido');
expect(connection.getExisting('dogs', 'fido')).equal(doc);

doc.destroy();
expect(this.connection.getExisting('dogs', 'fido')).equal(undefined);
doc.destroy(function(err) {
if (err) return done(err);
expect(connection.getExisting('dogs', 'fido')).equal(undefined);

var doc2 = this.connection.get('dogs', 'fido');
expect(doc).not.equal(doc2);
var doc2 = connection.get('dogs', 'fido');
expect(doc).not.equal(doc2);
done();
});

// destroy is async
expect(connection.getExisting('dogs', 'fido')).equal(doc);
});

it('getting then destroying then getting returns a new doc object', function() {
var doc = this.connection.get('dogs', 'fido');
doc.destroy();
var doc2 = this.connection.get('dogs', 'fido');
expect(doc).not.equal(doc2);
expect(doc).eql(doc2);
it('getting then destroying then getting returns a new doc object', function(done) {
var connection = this.connection;
var doc = connection.get('dogs', 'fido');
doc.destroy(function(err) {
if (err) return done(err);
var doc2 = connection.get('dogs', 'fido');
expect(doc).not.equal(doc2);
expect(doc).eql(doc2);
done();
});
});

it('doc.destroy() calls back', function(done) {
it('doc.destroy() works without a callback', function() {
var doc = this.connection.get('dogs', 'fido');
doc.destroy(done);
doc.destroy();
});

describe('applyStack', function() {
Expand Down