Skip to content

Commit

Permalink
test(discriminator): repro #7808
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed May 22, 2019
1 parent dc56c43 commit e91fca1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/model.discriminator.test.js
Expand Up @@ -529,6 +529,33 @@ describe('model', function() {
});
});

it('embedded discriminator with numeric type (gh-7808)', function() {
const typesSchema = Schema({
type: { type: Number }
}, { discriminatorKey:'type',_id:false });

const mainSchema = Schema({
types:[typesSchema]
});

mainSchema.path('types').discriminator(1,
Schema({ foo: { type: String, default: 'bar' } }));
mainSchema.path('types').discriminator(2,
Schema({ hello: { type: String, default: 'world' } }));

const Model = db.model('gh7808', mainSchema);

return co(function*() {
yield Model.create({
types: [{ type: 1 }, { type: 2 }]
});
const fromDb = yield Model.collection.findOne();
assert.equal(fromDb.types.length, 2);
assert.equal(fromDb.types[0].foo, 'bar');
assert.equal(fromDb.types[1].hello, 'world');
});
});

it('supports clone() (gh-4983)', function(done) {
var childSchema = new Schema({
name: String
Expand Down

0 comments on commit e91fca1

Please sign in to comment.