Just discovered a bug, tests written on it

pull/2/head
Louis Chatriot 11 years ago
parent 0e7fde88d2
commit 8852e93974
  1. 56
      lib/datastore.js
  2. 4
      lib/indexes.js
  3. 12
      test/db.test.js

@ -493,5 +493,61 @@ db.insert({ tag: ['a', 'b', 'c'] }, function () {
}); });
*/ */
/*
var db = new Datastore({ inMemoryOnly: true });
db.ensureIndex({ fieldName: 'a', unique: true });
db.insert({ a: 4 }, function () {
db.insert({ a: 5 }, function () {
db.insert({ a: 6 }, function () {
db.find({}, function (err, docs) {
console.log(docs);
db.update({}, { $set: { a: 42 } }, { multi: true }, function (err) {
console.log(err);
db.find({}, function (err, docs) {
// FAIL
// The first document was modified and the modification was not roll back when the
// unique constraint was triggered on the second modif
console.log(docs);
});
});
});
});
});
});
*/
var db = new Datastore({ inMemoryOnly: true });
db.insert({ a: [4] }, function () {
db.insert({ a: [5] }, function () {
db.insert({ a: 6 }, function () {
db.find({}, function (err, docs) {
console.log(docs);
db.update({}, { $push: { a: 42 } }, { multi: true }, function (err) {
console.log(err);
db.find({}, function (err, docs) {
console.log(docs);
});
});
});
});
});
});
module.exports = Datastore; module.exports = Datastore;

@ -63,6 +63,8 @@ Index.prototype.insert = function (doc) {
/** /**
* Insert an array of documents in the index * Insert an array of documents in the index
* If a constraint is violated, an error should be thrown and the changes rolled back * If a constraint is violated, an error should be thrown and the changes rolled back
*
* @API private
*/ */
Index.prototype.insertMultipleDocs = function (docs) { Index.prototype.insertMultipleDocs = function (docs) {
var i, error, failingI; var i, error, failingI;
@ -130,6 +132,8 @@ Index.prototype.update = function (oldDoc, newDoc) {
* If a constraint is violated, the changes need to be rolled back * If a constraint is violated, the changes need to be rolled back
* and an error thrown * and an error thrown
* @param {Array of oldDoc, newDoc pairs} pairs * @param {Array of oldDoc, newDoc pairs} pairs
*
* @API private
*/ */
Index.prototype.updateMultipleDocs = function (pairs) { Index.prototype.updateMultipleDocs = function (pairs) {
var i, failingI, error; var i, failingI, error;

@ -569,7 +569,7 @@ describe('Database', function () {
}); });
describe('Update', function () { describe.only('Update', function () {
it("If the query doesn't match anything, database is not modified", function (done) { it("If the query doesn't match anything, database is not modified", function (done) {
async.waterfall([ async.waterfall([
@ -976,6 +976,16 @@ describe('Database', function () {
}); });
}); });
it('If a multi update fails on one document, previous updates should be rolled back', function (done) {
throw 'TODO';
done();
});
it('If an index constraint is violated by an update, all changes should be rolled back', function (done) {
throw 'TODO';
done();
});
}); // ==== End of 'Update' ==== // }); // ==== End of 'Update' ==== //

Loading…
Cancel
Save