Skip to content

Commit

Permalink
Added tests for empty array default and auto-defaulting to an empty a…
Browse files Browse the repository at this point in the history
…rray. Refutes Issue 250.
  • Loading branch information
bnoguchi committed Feb 16, 2011
1 parent 66cced4 commit 3fb69a2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/model.test.js
Expand Up @@ -160,6 +160,28 @@ module.exports = {
db.close();
},

'test a model that defaults an Array attributes to an empty array': function () {
var db = start()
, DefaultZeroCardArraySchema = new Schema({
arr: {type: Array, cast: String, default: []}
});
mongoose.model('DefaultZeroCardArray', DefaultZeroCardArraySchema);
var DefaultZeroCardArray = db.model('DefaultZeroCardArray', collection);
var arr = new DefaultZeroCardArray();
arr.get('arr').should.have.length(0);
arr.arr.should.have.length(0);
db.close();
},

'test that arrays auto-default to the empty array': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);

var post = new BlogPost();
post.numbers.should.have.length(0);
db.close();
},

'test instantiating a model with a hash that maps to at least 1 null value': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
Expand Down

0 comments on commit 3fb69a2

Please sign in to comment.