Skip to content

Commit

Permalink
(#4098) - WIP - remove deprecated onChange and complete
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Aug 1, 2015
1 parent 43d50f6 commit c5ee426
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 558 deletions.
7 changes: 0 additions & 7 deletions lib/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ function Changes(db, opts, callback) {
oldComplete(err);
});
}
var oldOnChange = opts.onChange;
if (oldOnChange) {
self.on('change', oldOnChange);
}
function onDestroy() {
self.cancel();
}
Expand Down Expand Up @@ -70,9 +66,6 @@ function Changes(db, opts, callback) {
};
});
self.once('cancel', function () {
if (oldOnChange) {
self.removeListener('change', oldOnChange);
}
db.removeListener('destroyed', onDestroy);
opts.complete(null, {status: 'cancelled'});
});
Expand Down
120 changes: 57 additions & 63 deletions tests/integration/test.attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2039,39 +2039,37 @@ adapters.forEach(function (adapter) {
should.not.exist(res.rows[0].doc._attachments,
'(allDocs) doc0 contains no attachments');
db.changes({
include_docs: true,
onChange: function (change) {
var i = +change.id.substr(3);
if (i === 0) {
should.not.exist(res.rows[0].doc._attachments,
'(onChange) doc0 contains no attachments');
} else {
var attachmentsNb =
typeof docs[i]._attachments !== 'undefined' ?
Object.keys(docs[i]._attachments).length : 0;
for (var j = 0; j < attachmentsNb; j++) {
res.rows[i].doc._attachments['att' + j].stub.should
.equal(true, '(onChange) doc' + i + ' contains att' + j +
' stub');
}
include_docs: true
}).on('change', function (change) {
var i = +change.id.substr(3);
if (i === 0) {
should.not.exist(res.rows[0].doc._attachments,
'(onChange) doc0 contains no attachments');
} else {
var attachmentsNb =
typeof docs[i]._attachments !== 'undefined' ?
Object.keys(docs[i]._attachments).length : 0;
for (var j = 0; j < attachmentsNb; j++) {
res.rows[i].doc._attachments['att' + j].stub.should
.equal(true, '(onChange) doc' + i + ' contains att' + j +
' stub');
}
},
complete: function (err, res) {
var attachmentsNb = 0;
res.results.sort(sort);
for (var i = 0; i < 3; i++) {
attachmentsNb = typeof docs[i]._attachments !== 'undefined' ?
Object.keys(docs[i]._attachments).length : 0;
for (var j = 0; j < attachmentsNb; j++) {
res.results[i].doc._attachments['att' + j].stub.should
.equal(true, '(complete) doc' + i + ' contains att' + j +
' stub');
}
}
}).on('complete', function (res) {
var attachmentsNb = 0;
res.results.sort(sort);
for (var i = 0; i < 3; i++) {
attachmentsNb = typeof docs[i]._attachments !== 'undefined' ?
Object.keys(docs[i]._attachments).length : 0;
for (var j = 0; j < attachmentsNb; j++) {
res.results[i].doc._attachments['att' + j].stub.should
.equal(true, '(complete) doc' + i + ' contains att' + j +
' stub');
}
should.not.exist(res.results[0].doc._attachments,
'(complete) doc0 contains no attachments');
done();
}
should.not.exist(res.results[0].doc._attachments,
'(complete) doc0 contains no attachments');
done();
});
});
});
Expand Down Expand Up @@ -2273,27 +2271,25 @@ adapters.forEach(function (adapter) {
function (done) {
var db = new PouchDB(dbs.name);
var changes = db.changes({
complete: function (err, result) {
result.status.should.equal('cancelled');
done();
},
live: true,
onChange: function (change) {
if (change.id === 'anotherdoc2') {
change.id.should.equal('anotherdoc2', 'Doc has been created');
db.get(change.id, { attachments: true }, function (err, doc) {
doc._attachments.should.be
.an('object', 'doc has attachments object');
should.exist(doc._attachments.mytext,
'doc has attachments attachment');
doc._attachments.mytext.data.should
.equal('TXl0ZXh0', 'doc has attachments attachment');
changes.cancel();
});
}
live: true
}).on('complete', function (result) {
result.status.should.equal('cancelled');
done();
}).on('change', function (change) {
if (change.id === 'anotherdoc2') {
change.id.should.equal('anotherdoc2', 'Doc has been created');
db.get(change.id, { attachments: true }, function (err, doc) {
doc._attachments.should.be
.an('object', 'doc has attachments object');
should.exist(doc._attachments.mytext,
'doc has attachments attachment');
doc._attachments.mytext.data.should
.equal('TXl0ZXh0', 'doc has attachments attachment');
changes.cancel();
});
}
});
var blob = testUtils.makeBlob('Mytext');
var blob = testUtils.makeBlob('Mytext');
db.putAttachment('anotherdoc2', 'mytext', blob, 'text/plain');
});

Expand All @@ -2305,22 +2301,20 @@ adapters.forEach(function (adapter) {

var changes = db.changes({
since: info.update_seq,
complete: function (err, result) {
result.status.should.equal('cancelled');
done();
},
live: true,
include_docs: true,
onChange: function (change) {
if (change.id === 'anotherdoc3') {
db.get(change.id, { attachments: true }, function (err, doc) {
doc._attachments.should.be.an('object',
'doc has attachments object');
should.exist(doc._attachments.mytext);
doc._attachments.mytext.data.should.equal('TXl0ZXh0');
changes.cancel();
});
}
}).on('complete', function (result) {
result.status.should.equal('cancelled');
done();
}).on('change', function (change) {
if (change.id === 'anotherdoc3') {
db.get(change.id, { attachments: true }, function (err, doc) {
doc._attachments.should.be.an('object',
'doc has attachments object');
should.exist(doc._attachments.mytext);
doc._attachments.mytext.data.should.equal('TXl0ZXh0');
changes.cancel();
});
}
});
var blob = testUtils.makeBlob('Mytext');
Expand Down
18 changes: 8 additions & 10 deletions tests/integration/test.basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,15 @@ adapters.forEach(function (adapter) {
var db = new PouchDB(dbs.name);
var changes = db.changes({
live: true,
include_docs: true,
onChange: function (change) {
if (change.doc._deleted) {
changes.cancel();
}
},
complete: function (err, result) {
result.status.should.equal('cancelled');
done();
include_docs: true
}).on('change', function (change) {
if (change.doc._deleted) {
changes.cancel();
}
});
}).on('complete', function (result) {
result.status.should.equal('cancelled');
done();
}).on('error', done);
db.post({ _id: 'somestuff' }, function (err, res) {
db.remove({
_id: res.id,
Expand Down
Loading

0 comments on commit c5ee426

Please sign in to comment.