Skip to content

Commit

Permalink
test(document): repro #5085
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 25, 2017
1 parent 64b4eb1 commit 2bbc59e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3870,6 +3870,32 @@ describe('document', function() {
});
});

it('post hooks on child subdocs run after save (gh-5085)', function(done) {
var ChildModelSchema = new mongoose.Schema({
text: {
type: String
}
});
ChildModelSchema.post('save', function(doc) {
doc.text = 'bar';
});
var ParentModelSchema = new mongoose.Schema({
children: [ChildModelSchema]
});

var Model = db.model('gh5085', ParentModelSchema);

Model.create({ children: [{ text: 'test' }] }, function(error) {
assert.ifError(error);
Model.findOne({}, function(error, doc) {
assert.ifError(error);
assert.equal(doc.children.length, 1);
assert.equal(doc.children[0].text, 'test');
done();
});
});
});

it('nested docs toObject() clones (gh-5008)', function(done) {
var schema = new mongoose.Schema({
sub: {
Expand Down

0 comments on commit 2bbc59e

Please sign in to comment.