From dce067b33209de884f58c53616a80521dff6441e Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 14 Nov 2017 22:56:41 -0800 Subject: [PATCH] test(document): repro #5807 --- test/document.test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/document.test.js b/test/document.test.js index 146844283b5..152a3902611 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -1908,6 +1908,38 @@ describe('document', function() { }); }); + it('single nested schema transform with save() (gh-5807)', function() { + var embeddedSchema = new Schema({ + test: String + }); + + var called = false; + embeddedSchema.options.toObject = { + transform: function(doc, ret) { + called = true; + delete ret.test; + return ret; + } + }; + var topLevelSchema = new Schema({ + embedded: embeddedSchema + }); + var MyModel = db.model('gh5807', topLevelSchema); + + return MyModel.create({}). + then(function(doc) { + doc.embedded = { test: '123' }; + return doc.save(); + }). + then(function(doc) { + return MyModel.findById(doc._id); + }). + then(function(doc) { + assert.equal(doc.embedded.test, '123'); + assert.ok(!called); + }); + }); + it('setters firing with objects on real paths (gh-2943)', function(done) { var M = mongoose.model('gh2943', { myStr: {