From 320d5f88b6194663925ba3febe72dd8819e29b77 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 1 Nov 2018 10:59:16 -0400 Subject: [PATCH] test(query): repro #7182 --- test/query.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/query.test.js b/test/query.test.js index 8445eae7e48..b99ebb191ab 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -3197,4 +3197,21 @@ describe('Query', function() { assert.equal(docs.length, 1); }); }); + + it('function defaults run after query result is inited (gh-7182)', function() { + const schema = new Schema({ kind: String, hasDefault: String }); + schema.path('hasDefault').default(function() { + return this.kind === 'test' ? 'success' : 'fail'; + }); + + return co(function*() { + const Model = db.model('gh7182', schema); + + yield Model.create({ kind: 'test' }); + yield Model.updateOne({}, { $unset: { hasDefault: 1 } }); + + const doc = yield Model.findOne(); + assert.equal(doc.hasDefault, 'success'); + }); + }); });