|
|
|
@ -569,7 +569,7 @@ describe('Database', function () { |
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe.only('Update', function () { |
|
|
|
|
describe('Update', function () { |
|
|
|
|
|
|
|
|
|
it("If the query doesn't match anything, database is not modified", function (done) { |
|
|
|
|
async.waterfall([ |
|
|
|
@ -977,14 +977,56 @@ describe('Database', function () { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('If a multi update fails on one document, previous updates should be rolled back', function (done) { |
|
|
|
|
throw 'TODO'; |
|
|
|
|
d.ensureIndex({ fieldName: 'a' }); |
|
|
|
|
d.insert({ a: 4 }, function (err, doc1) { |
|
|
|
|
d.insert({ a: 5 }, function (err, doc2) { |
|
|
|
|
d.insert({ a: 'abc' }, function (err, doc3) { |
|
|
|
|
// With this query, candidates are always returned in the order 4, 5, 'abc' so it's always the last one which fails
|
|
|
|
|
d.update({ a: { $in: [4, 5, 'abc'] } }, { $inc: { a: 10 } }, { multi: true }, function (err) { |
|
|
|
|
assert.isDefined(err); |
|
|
|
|
|
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
|
var d1 = _.find(docs, function (doc) { return doc._id === doc1._id }) |
|
|
|
|
, d2 = _.find(docs, function (doc) { return doc._id === doc2._id }) |
|
|
|
|
, d3 = _.find(docs, function (doc) { return doc._id === doc3._id }) |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
// All changes rollbacked, including those that didn't trigger an error
|
|
|
|
|
d1.a.should.equal(4); |
|
|
|
|
d2.a.should.equal(5); |
|
|
|
|
d3.a.should.equal('abc'); |
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it.only('If an index constraint is violated by an update, all changes should be rolled back', function (done) { |
|
|
|
|
d.ensureIndex({ fieldName: 'a', unique: true }); |
|
|
|
|
d.insert({ a: 4 }, function (err, doc1) { |
|
|
|
|
d.insert({ a: 5 }, function (err, doc2) { |
|
|
|
|
// With this query, candidates are always returned in the order 4, 5, 'abc' so it's always the last one which fails
|
|
|
|
|
d.update({ a: { $in: [4, 5, 'abc'] } }, { $set: { a: 10 } }, { multi: true }, function (err) { |
|
|
|
|
assert.isDefined(err); |
|
|
|
|
|
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
|
var d1 = _.find(docs, function (doc) { return doc._id === doc1._id }) |
|
|
|
|
, d2 = _.find(docs, function (doc) { return doc._id === doc2._id }) |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
// All changes rollbacked, including those that didn't trigger an error
|
|
|
|
|
d1.a.should.equal(4); |
|
|
|
|
d2.a.should.equal(5); |
|
|
|
|
|
|
|
|
|
it('If an index constraint is violated by an update, all changes should be rolled back', function (done) { |
|
|
|
|
throw 'TODO'; |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}); // ==== End of 'Update' ==== //
|
|
|
|
|
|
|
|
|
|