Skip to content

Commit

Permalink
test(document): repro #4145
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed May 13, 2016
1 parent bb98b2e commit 8d28cdb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/schema.validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,50 @@ describe('schema', function() {
});
});

it('no double validation on set nested docarray (gh-4145)', function(done) {
var calls = 0;
var myValidator = function() {
++calls;
return true;
}
var InnerSchema = new mongoose.Schema({
myfield: {
type: String,
validate: {
validator: myValidator,
message: 'Message'
}
},
sibling: String
});

var MySchema = new mongoose.Schema({
nest: {
myarray: [InnerSchema]
},
rootSibling: String
});

var Model = mongoose.model('gh4145', MySchema);

var instance = new Model({
rootSibling: 'This is the root sibling'
});
// Direct object assignment
instance.nest = {
myarray: [{
myfield: 'This is my field',
sibling: 'This is the nested sibling'
}]
};

instance.validate(function(error) {
assert.ifError(error);
assert.equal(calls, 1);
done();
});
});

it('returns cast errors', function(done) {
var breakfastSchema = new Schema({
eggs: Number
Expand Down

0 comments on commit 8d28cdb

Please sign in to comment.