Skip to content

Commit

Permalink
test(document): repro #7585
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 24, 2019
1 parent a4bf0cb commit fb8b39a
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5157,7 +5157,7 @@ describe('document', function() {

const noteSchema = new Schema({
title: { type: String, required: true },
body: { type: contentSchema }
body: contentSchema
});

const Note = db.model('gh5363', noteSchema);
Expand Down Expand Up @@ -7011,4 +7011,34 @@ describe('document', function() {
assert.equal(doc.name, 'test2');
});
});

it('setters that modify `this` should work on single nested when overwriting (gh-7585)', function() {
const NameSchema = new Schema({
full: {
type: String,
set: function(v) {
this.first = 'foo';
this.last = 'bar';
return v + ' baz';
}
},
first: String,
last: String
}, { _id: false });

const User = db.model('gh7585', new Schema({
name: {
type: NameSchema,
default: {}
}
}));

const s = new User();
s.name = { full: 'test' };
assert.equal(s.name.first, 'foo');
assert.equal(s.name.last, 'bar');
assert.equal(s.name.full, 'test baz');

return Promise.resolve();
});
});

0 comments on commit fb8b39a

Please sign in to comment.