Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#1115) - Add event emitter for DB change events
- Loading branch information
1 parent
e8d8c62
commit 1e2601f
Showing
11 changed files
with
247 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
'use strict'; | ||
|
||
var adapters = [ | ||
'http-1', | ||
'local-1' | ||
]; | ||
adapters.forEach(function (adapter) { | ||
describe('test.events.js-' + adapter, function () { | ||
//we can't use the same db becasue | ||
var i = 0; | ||
var dbs = {}; | ||
beforeEach(function () { | ||
dbs.name = testUtils.adapterUrl(adapter, 'events_tests' + i++); | ||
}); | ||
|
||
afterEach(function (done) { | ||
PouchDB.destroy(dbs.name, done); | ||
}); | ||
|
||
it('PouchDB emits creation event', function (done) { | ||
PouchDB.once('created', function (name) { | ||
name.should.equal(dbs.name, 'should be same thing'); | ||
done(); | ||
}); | ||
new PouchDB(dbs.name); | ||
}); | ||
it('PouchDB emits destruction event', function (done) { | ||
new PouchDB(dbs.name + 1, function () { | ||
PouchDB.destroy(dbs.name + 1); | ||
}).once('destroyed', function () { | ||
new PouchDB(dbs.name, function () { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('emit creation event', function (done) { | ||
var db = new PouchDB(dbs.name).on('created', function (newDB) { | ||
db.should.equal(newDB, 'should be same thing'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('emit changes event', function (done) { | ||
new PouchDB(dbs.name, function (err, db) { | ||
var id = 'emiting'; | ||
var obj = { | ||
something: 'here', | ||
somethingElse: 'overHere' | ||
}; | ||
db.on('change', function (change) { | ||
change.seq.should.equal(1, 'changed'); | ||
change.id.should.equal('emiting'); | ||
done(err); | ||
}); | ||
db.put(obj, id); | ||
}); | ||
}); | ||
|
||
it('emit create event', function (done) { | ||
new PouchDB(dbs.name, function (err, db) { | ||
var id = 'creating'; | ||
var obj = { | ||
something: 'here', | ||
somethingElse: 'overHere' | ||
}; | ||
db.on('create', function (change) { | ||
change.id.should.equal('creating'); | ||
change.seq.should.equal(1, 'created'); | ||
done(err); | ||
}); | ||
db.put(obj, id); | ||
}); | ||
}); | ||
|
||
it('emit update event', function (done) { | ||
new PouchDB(dbs.name, function (err, db) { | ||
var id = 'updating'; | ||
var obj = { | ||
something: 'here', | ||
somethingElse: 'overHere' | ||
}; | ||
db.on('update', function (change) { | ||
change.id.should.equal('updating'); | ||
change.seq.should.equal(2, 'seq 2, updated'); | ||
done(err); | ||
}); | ||
|
||
db.put(obj, id).then(function (doc) { | ||
db.put({'something': 'else'}, id, doc.rev); | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
it('emit delete event', function (done) { | ||
new PouchDB(dbs.name, function (err, db) { | ||
var id = 'emiting'; | ||
var obj = { | ||
something: 'here', | ||
somethingElse: 'overHere' | ||
}; | ||
db.on('delete', function (change) { | ||
change.seq.should.equal(2, 'deleted'); | ||
change.id.should.equal('emiting'); | ||
done(err); | ||
}); | ||
|
||
db.put(obj, id).then(function (doc) { | ||
db.remove({ | ||
_id: id, | ||
_rev: doc.rev | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters