Test on previous update behaviour corrected

pull/2/head
Louis Chatriot 12 years ago
parent 39050a45d4
commit 17f02e0381
  1. 2
      lib/datastore.js
  2. 33
      test/db.test.js
  3. 2
      test/indexes.test.js

@ -143,7 +143,7 @@ Datastore.prototype.updateIndexes = function (oldDoc, newDoc) {
// If an error happened, we need to rollback the insert on all other indexes // If an error happened, we need to rollback the insert on all other indexes
if (error) { if (error) {
for (i = 0; i < failingIndex; i += 1) { for (i = 0; i < failingIndex; i += 1) {
this.indexes[keys[i]].remove(doc); this.indexes[keys[i]].revertUpdate(oldDoc, newDoc);
} }
throw error; throw error;

@ -1491,24 +1491,38 @@ describe('Database', function () {
}); // ==== End of 'Indexing newly inserted documents' ==== // }); // ==== End of 'Indexing newly inserted documents' ==== //
describe.skip('Updating indexes upon document update', function () { describe.only('Updating indexes upon document update', function () {
it('Updating docs still works as before with an index', function (done) { it('Updating docs still works as before with indexing', function (done) {
d.ensureIndex({ fieldName: 'a' }); d.ensureIndex({ fieldName: 'a' });
d.insert({ a: 1, b: 'hello' }, function (err, doc1) { d.insert({ a: 1, b: 'hello' }, function (err, _doc1) {
d.insert({ a: 2, b: 'si' }, function (err, doc2) { d.insert({ a: 2, b: 'si' }, function (err, _doc2) {
d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) { d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) {
var data = d.getAllData()
, doc1 = _.find(data, function (doc) { return doc._id === _doc1._id; })
, doc2 = _.find(data, function (doc) { return doc._id === _doc2._id; })
;
assert.isNull(err); assert.isNull(err);
nr.should.equal(1); nr.should.equal(1);
//console.log(d.data);
return done(); data.length.should.equal(2);
assert.deepEqual(doc1, { a: 456, b: 'no', _id: _doc1._id });
assert.deepEqual(doc2, { a: 2, b: 'si', _id: _doc2._id });
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function (err, nr) {
var data = d.getAllData()
, doc1 = _.find(data, function (doc) { return doc._id === _doc1._id; })
, doc2 = _.find(data, function (doc) { return doc._id === _doc2._id; })
;
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function () {
assert.isNull(err); assert.isNull(err);
nr.should.equal(2); nr.should.equal(2);
data.length.should.equal(2);
assert.deepEqual(doc1, { a: 466, b: 'same', _id: _doc1._id });
assert.deepEqual(doc2, { a: 12, b: 'same', _id: _doc2._id });
done(); done();
}); });
@ -1554,10 +1568,7 @@ describe('Database', function () {
}); });
}); });
it.skip('If an update violates a contraints, nothing is done', function (done) { it.skip('If an update violates a contraint, all changes are rolled back and an error is thrown', function (done) {
});
it.skip('Updates still work with indexing', function (done) {
}); });
}); // ==== End of 'Updating indexes upon document update' ==== // }); // ==== End of 'Updating indexes upon document update' ==== //

@ -330,7 +330,7 @@ describe('Indexes', function () {
assert.deepEqual(idx.tree.search('world'), [noChange]); assert.deepEqual(idx.tree.search('world'), [noChange]);
}); });
it('Can revert normal and batch updates', function () { it('Can revert simple and batch updates', function () {
var idx = new Index({ fieldName: 'tf' }) var idx = new Index({ fieldName: 'tf' })
, doc1 = { a: 5, tf: 'hello' } , doc1 = { a: 5, tf: 'hello' }
, doc2 = { a: 8, tf: 'world' } , doc2 = { a: 8, tf: 'world' }

Loading…
Cancel
Save