Skip to content

Commit

Permalink
test(document): repro #5807
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 15, 2017
1 parent 95e548e commit dce067b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,38 @@ describe('document', function() {
});
});

it('single nested schema transform with save() (gh-5807)', function() {
var embeddedSchema = new Schema({
test: String
});

var called = false;
embeddedSchema.options.toObject = {
transform: function(doc, ret) {
called = true;
delete ret.test;
return ret;
}
};
var topLevelSchema = new Schema({
embedded: embeddedSchema
});
var MyModel = db.model('gh5807', topLevelSchema);

return MyModel.create({}).
then(function(doc) {
doc.embedded = { test: '123' };
return doc.save();
}).
then(function(doc) {
return MyModel.findById(doc._id);
}).
then(function(doc) {
assert.equal(doc.embedded.test, '123');
assert.ok(!called);
});
});

it('setters firing with objects on real paths (gh-2943)', function(done) {
var M = mongoose.model('gh2943', {
myStr: {
Expand Down

0 comments on commit dce067b

Please sign in to comment.