From d467f05e1a8c0468281e94c619c39dcb293a6835 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 19 Apr 2017 22:49:41 -0600 Subject: [PATCH] test(document): repro #5162 --- test/document.test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/document.test.js b/test/document.test.js index 81259ce0864..f26e9dfc64b 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -3959,6 +3959,33 @@ describe('document', function() { done(); }); + it('handles array subdocs with single nested subdoc default (gh-5162)', function(done) { + var RatingsItemSchema = new mongoose.Schema({ + value: Number + }, { versionKey: false, _id: false }); + + var RatingsSchema = new mongoose.Schema({ + ratings: { + type: RatingsItemSchema, + default: { id: 1, value: 0 } + }, + _id: false + }); + + var RestaurantSchema = new mongoose.Schema({ + menu: { + type: [RatingsSchema] + } + }); + + var Restaurant = db.model('gh5162', RestaurantSchema); + + // Should not throw + var r = new Restaurant(); + assert.deepEqual(r.toObject().menu, []); + done(); + }); + it('modify multiple subdoc paths (gh-4405)', function(done) { var ChildObjectSchema = new Schema({ childProperty1: String,