Skip to content

Commit

Permalink
fix(document): dont trigger .then() deprecated warning when calling d…
Browse files Browse the repository at this point in the history
…oc.remove()

Fix #4291
  • Loading branch information
vkarpov15 committed Jul 21, 2016
1 parent e0039d8 commit c320fa7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
18 changes: 1 addition & 17 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,28 +1143,12 @@ Document.prototype.isSelected = function isSelected(path) {
*/

Document.prototype.validate = function(options, callback) {
var _this = this;
var Promise = PromiseProvider.get();
if (typeof options === 'function') {
callback = options;
options = null;
}

if (options && options.__noPromise) {
this.$__validate(callback);
return;
}

return new Promise.ES6(function(resolve, reject) {
_this.$__validate(function(error) {
callback && callback(error);
if (error) {
reject(error);
return;
}
resolve();
});
});
this.$__validate(callback);
};

/*!
Expand Down
10 changes: 10 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ Object.defineProperty(Schema.prototype, '_defaultMiddleware', {
});
}
},
{
kind: 'pre',
hook: 'validate',
isAsync: true,
fn: function(next, done) {
// Hack to ensure that we always wrap validate() in a promise
next();
done();
}
},
{
kind: 'pre',
hook: 'remove',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"async": "1.5.2",
"bson": "~0.4.23",
"hooks-fixed": "1.1.0",
"hooks-fixed": "1.2.0",
"kareem": "1.1.3",
"mongodb": "2.1.18",
"mpath": "0.2.1",
Expand Down
2 changes: 1 addition & 1 deletion test/model.discriminator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ describe('model', function() {
});

it('merges callQueue with base queue defined before discriminator types callQueue', function(done) {
assert.equal(Employee.schema.callQueue.length, 5);
assert.equal(Employee.schema.callQueue.length, 6);
// PersonSchema.post('save')
assert.strictEqual(Employee.schema.callQueue[0], Person.schema.callQueue[0]);

Expand Down
6 changes: 3 additions & 3 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,15 @@ describe('schema', function() {

Tobi.pre('save', function() {
});
assert.equal(Tobi.callQueue.length, 4);
assert.equal(Tobi.callQueue.length, 5);

Tobi.post('save', function() {
});
assert.equal(Tobi.callQueue.length, 5);
assert.equal(Tobi.callQueue.length, 6);

Tobi.pre('save', function() {
});
assert.equal(Tobi.callQueue.length, 6);
assert.equal(Tobi.callQueue.length, 7);
done();
});
});
Expand Down

0 comments on commit c320fa7

Please sign in to comment.