Skip to content

Commit

Permalink
test(model): repro #6967
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 15, 2018
1 parent 8a178ad commit 4108366
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/model.test.js
Expand Up @@ -5838,6 +5838,7 @@ describe('Model', function() {
test.save().then(handler);
test.save().catch(error);
});

it('allows calling save in a post save hook (gh-6611)', function() {
let called = 0;
const noteSchema = new Schema({
Expand All @@ -5861,4 +5862,36 @@ describe('Model', function() {
});
});
});

it('dropDatabase() after init allows re-init (gh-6967)', function() {
const Model = db.model('gh6640', new Schema({
name: { type: String, index: true }
}));

return co(function*() {
yield Model.init();

yield db.dropDatabase();

assert.ok(!Model.$init);

let threw = false;

try {
yield Model.listIndexes();
} catch (err) {
assert.ok(err.message.indexOf('Database mongoose_test') !== -1,
err.message);
threw = true;
}
assert.ok(threw);

yield Model.init();

const indexes = yield Model.listIndexes();

assert.equal(indexes.length, 2);
assert.deepEqual(indexes[1].key, { name: 1});
});
});
});

0 comments on commit 4108366

Please sign in to comment.