Skip to content

Commit b186b93

Browse files
committed
test(populate): reuse collections where possible for populate() tests
Re: #8481
1 parent b5f744e commit b186b93

File tree

2 files changed

+627
-725
lines changed

2 files changed

+627
-725
lines changed

test/model.populate.setting.test.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ const random = utils.random;
1717
const Schema = mongoose.Schema;
1818
const DocObjectId = mongoose.Types.ObjectId;
1919

20-
/**
21-
* Setup.
22-
*/
23-
24-
const posts = 'blogposts_' + random();
25-
const users = 'users_' + random();
26-
2720
/**
2821
* Tests.
2922
*/
@@ -49,24 +42,21 @@ describe('model: populate:', function() {
4942

5043
Object.keys(types).forEach(function(id) {
5144
describe('should not cast to _id of type ' + id, function() {
52-
let refuser;
5345
let db;
5446
let B, U;
5547
let u1;
5648
let b1, b2;
5749

5850
before(function(done) {
59-
refuser = 'RefUser-' + id;
60-
6151
const bSchema = new Schema({
6252
title: String,
63-
fans: [{type: id, ref: refuser}],
53+
fans: [{type: id, ref: 'User'}],
6454
adhoc: [{subdoc: id, subarray: [{things: [id]}]}],
65-
_creator: {type: id, ref: refuser},
55+
_creator: {type: id, ref: 'User'},
6656
embed: [{
67-
other: {type: id, ref: refuser},
68-
array: [{type: id, ref: refuser}],
69-
nested: [{subdoc: {type: id, ref: refuser}}]
57+
other: {type: id, ref: 'User'},
58+
array: [{type: id, ref: 'User'}],
59+
nested: [{subdoc: {type: id, ref: 'User'}}]
7060
}]
7161
});
7262

@@ -77,8 +67,8 @@ describe('model: populate:', function() {
7767
});
7868

7969
db = start();
80-
B = db.model('RefBlogPost-' + id, bSchema, posts + random());
81-
U = db.model(refuser, uSchema, users + random());
70+
B = db.model('BlogPost', bSchema);
71+
U = db.model('User', uSchema);
8272

8373
U.create({
8474
_id: construct[id](),
@@ -128,8 +118,8 @@ describe('model: populate:', function() {
128118
it('if a document', function(done) {
129119
const query = B.findById(b1).
130120
populate('fans _creator embed.other embed.array embed.nested.subdoc').
131-
populate({path: 'adhoc.subdoc', model: refuser}).
132-
populate({path: 'adhoc.subarray.things', model: refuser});
121+
populate({path: 'adhoc.subdoc', model: 'User'}).
122+
populate({path: 'adhoc.subarray.things', model: 'User'});
133123
query.exec(function(err, doc) {
134124
assert.ifError(err);
135125

@@ -229,8 +219,8 @@ describe('model: populate:', function() {
229219
it('if an object', function(done) {
230220
B.findById(b2)
231221
.populate('fans _creator embed.other embed.array embed.nested.subdoc')
232-
.populate({path: 'adhoc.subdoc', model: refuser})
233-
.populate({path: 'adhoc.subarray.things', model: refuser})
222+
.populate({path: 'adhoc.subdoc', model: 'User'})
223+
.populate({path: 'adhoc.subarray.things', model: 'User'})
234224
.exec(function(err, doc) {
235225
assert.ifError(err);
236226

0 commit comments

Comments
 (0)