forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.documentarray.test.js
36 lines (29 loc) · 1.01 KB
/
schema.documentarray.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Module dependencies.
*/
var start = require('./common')
, mongoose = start.mongoose
, assert = require('assert')
, random = require('../lib/utils').random
, Schema = mongoose.Schema
/**
* Test.
*/
describe('schema.documentarray', function(){
it('defaults should be preserved', function(done){
var child = new Schema({ title: String })
var schema1 = new Schema({ x: { type: [child], default: [{ title: 'Prometheus'}] }});
var schema2 = new Schema({ x: { type: [child], default: { title: 'Prometheus'} }});
var schema3 = new Schema({ x: { type: [child], default: function(){return [{ title: 'Prometheus'}]} }});
var M = mongoose.model('DefaultDocArrays1', schema1);
var N = mongoose.model('DefaultDocArrays2', schema2);
var O = mongoose.model('DefaultDocArrays3', schema3);
[M,N,O].forEach(function (M) {
var m = new M;
assert.ok(Array.isArray(m.x));
assert.equal(1, m.x.length);
assert.equal('Prometheus', m.x[0].title);
});
done();
})
})