Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add documentarray defaults test

  • Loading branch information...
commit e013293df22bdb6f71fe51ae96505f4a487d85d5 1 parent 17ff241
@aheckmann aheckmann authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 test/schema.documentarray.test.js
View
37 test/schema.documentarray.test.js
@@ -0,0 +1,37 @@
+
+/**
+ * Module dependencies.
+ */
+
+var start = require('./common')
+ , mongoose = start.mongoose
+ , assert = require('assert')
+ , random = require('../lib/utils').random
+ , Schema = mongoose.Schema
+
+/**
+ * Test.
+ */
+
+module.exports = {
+
+ 'documentarray defaults should be preserved': function () {
+ 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);
+ });
+ }
+
+};
Please sign in to comment.
Something went wrong with that request. Please try again.