From 510f5ef6aca71f062c02b2b13b3dd69c6d0114c2 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 3 Mar 2014 15:52:49 -0800 Subject: [PATCH] Check the Array type See https://github.com/strongloop/loopback-connector-mongodb/issues/21 --- lib/list.js | 5 +++++ test/datatype.test.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/list.js b/lib/list.js index d679d570..2a2da03a 100644 --- a/lib/list.js +++ b/lib/list.js @@ -1,4 +1,5 @@ var util = require('util'); +var Any = require('./types').Types.Any; module.exports = List; @@ -32,6 +33,10 @@ function List(items, itemType, parent) { itemType = itemType[0]; } + if(itemType === Array) { + itemType = Any; + } + Object.defineProperty(arr, 'itemType', { writable: true, enumerable: false, diff --git a/test/datatype.test.js b/test/datatype.test.js index 4db0d506..13f83a20 100644 --- a/test/datatype.test.js +++ b/test/datatype.test.js @@ -13,6 +13,7 @@ describe('datatypes', function () { num: Number, bool: Boolean, list: {type: [String]}, + arr: Array }); db.automigrate(function () { Model.destroyAll(done); @@ -23,25 +24,30 @@ describe('datatypes', function () { var d = new Date, id; Model.create({ - str: 'hello', date: d, num: '3', bool: 1, list: ['test'] + str: 'hello', date: d, num: '3', bool: 1, list: ['test'], arr: [1, 'str'] }, function (err, m) { should.not.exist(err); should.exist(m && m.id); m.str.should.be.a('string'); m.num.should.be.a('number'); m.bool.should.be.a('boolean'); + m.list[0].should.be.equal('test'); + m.arr[0].should.be.equal(1); + m.arr[1].should.be.equal('str'); id = m.id; testFind(testAll); }); function testFind(next) { - debugger; Model.findById(id, function (err, m) { should.not.exist(err); should.exist(m); m.str.should.be.a('string'); m.num.should.be.a('number'); m.bool.should.be.a('boolean'); + m.list[0].should.be.equal('test'); + m.arr[0].should.be.equal(1); + m.arr[1].should.be.equal('str'); m.date.should.be.an.instanceOf(Date); m.date.toString().should.equal(d.toString(), 'Time must match'); next();