Added error handling for persist operation hook (#1531)
Unrelated CI failures. -.-
This commit is contained in:
parent
943fed851e
commit
07f0310d34
|
@ -3131,6 +3131,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
|
|||
options: options,
|
||||
};
|
||||
Model.notifyObserversOf('persist', ctx, function(err) {
|
||||
if (err) return cb(err);
|
||||
invokeConnectorMethod(connector, 'replaceById', Model, [id, Model._forDB(context.data)],
|
||||
options, replaceCallback);
|
||||
});
|
||||
|
@ -3327,6 +3328,7 @@ function(data, options, cb) {
|
|||
options: options,
|
||||
};
|
||||
Model.notifyObserversOf('persist', ctx, function(err) {
|
||||
if (err) return cb(err);
|
||||
invokeConnectorMethod(connector, 'updateAttributes', Model,
|
||||
[getIdValue(Model, inst), Model._forDB(context.data)],
|
||||
options, updateAttributesCallback);
|
||||
|
|
|
@ -1489,6 +1489,16 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
|||
});
|
||||
});
|
||||
|
||||
it('emits error when `persist` hook fails', function(done) {
|
||||
TestModel.observe('persist', nextWithError(expectedError));
|
||||
|
||||
TestModel.settings.updateOnLoad = true;
|
||||
existingInstance.updateAttributes({name: 'test'}, function(err, instance) {
|
||||
[err].should.eql([expectedError]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('triggers `loaded` hook', function(done) {
|
||||
TestModel.observe('loaded', ctxRecorder.recordAndNext());
|
||||
existingInstance.updateAttributes({name: 'changed'}, function(err) {
|
||||
|
|
Loading…
Reference in New Issue