Skip to content

Commit

Permalink
test(model): repro #5147
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Apr 19, 2017
1 parent 551c0a7 commit 115e85d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/model.discriminator.test.js
Expand Up @@ -508,6 +508,33 @@ describe('model', function() {
done();
});

it('copies query hooks (gh-5147)', function(done) {
var options = { discriminatorKey: 'kind' };

var eventSchema = new mongoose.Schema({ time: Date }, options);
var eventSchemaCalls = 0;
eventSchema.pre('findOneAndUpdate', function() {
++eventSchemaCalls;
});

var Event = db.model('gh5147', eventSchema);

var clickedEventSchema = new mongoose.Schema({ url: String }, options);
var clickedEventSchemaCalls = 0;
clickedEventSchema.pre('findOneAndUpdate', function() {
++clickedEventSchemaCalls;
});
var ClickedLinkEvent = Event.discriminator('gh5147_0', clickedEventSchema);

ClickedLinkEvent.findOneAndUpdate({}, { time: new Date() }, {}).
exec(function(error) {
assert.ifError(error);
assert.equal(eventSchemaCalls, 1);
assert.equal(clickedEventSchemaCalls, 1);
done();
});
});

it('embedded discriminators with $push (gh-5009)', function(done) {
var eventSchema = new Schema({ message: String },
{ discriminatorKey: 'kind', _id: false });
Expand Down

0 comments on commit 115e85d

Please sign in to comment.