diff --git a/test/document.test.js b/test/document.test.js index a36ae60e55e..f14c3762eca 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -4984,6 +4984,27 @@ describe('document', function() { done(); }); + it('Handles setting populated path set via `Document#populate()` (gh-7302)', function() { + var authorSchema = new Schema({ name: String }); + var bookSchema = new Schema({ + author: { type: mongoose.Schema.Types.ObjectId, ref: 'gh7302_Author' } + }); + + var Author = db.model('gh7302_Author', authorSchema); + var Book = db.model('gh7302_Book', bookSchema); + + return Author.create({ name: 'Victor Hugo' }). + then(author => Book.create({ author: author._id })). + then(() => Book.findOne()). + then(doc => doc.populate('author').execPopulate()). + then(doc => { + doc.author = {}; + assert.ok(!doc.author.name); + assert.ifError(doc.validateSync()); + }); + }); + + it('Single nested subdocs using discriminator can be modified (gh-5693)', function(done) { var eventSchema = new Schema({ message: String }, { discriminatorKey: 'kind',