From ab668dabb7d6f08962ceed11d2dce06e0f21f30c Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 6 Nov 2017 19:00:45 -0800 Subject: [PATCH] test(model): repro #5779 --- test/versioning.test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/versioning.test.js b/test/versioning.test.js index f60976975b1..db2e9854dc3 100644 --- a/test/versioning.test.js +++ b/test/versioning.test.js @@ -526,4 +526,31 @@ describe('versioning', function() { done(); }); }); + + it('copying doc works (gh-5779)', function(done) { + var schema = new Schema({ subdocs: [{ a: Number }] }); + var M = db.model('gh5779', schema, 'gh5779'); + var m = new M({ subdocs: [] }); + var m2; + + m.save(). + then(function() { + m2 = new M(m); + m2.subdocs.push({ a: 2 }); + return m2.save(); + }). + then(function() { + m2.subdocs[0].a = 3; + return m2.save(); + }). + then(function() { + assert.equal(m2.subdocs[0].a, 3); + return M.findById(m._id); + }). + then(function(doc) { + assert.equal(doc.subdocs[0].a, 3); + done(); + }). + catch(done); + }); });