Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add failing test for querying array type with single value

  • Loading branch information...
commit 8bac66f6cb3182bdb0e2c98b102d641e34e969a6 1 parent 147f385
@aheckmann aheckmann authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 test/query.test.js
View
43 test/query.test.js
@@ -601,6 +601,49 @@ module.exports = {
params.numbers.$ne[0].should.eql(10000);
},
+ 'Query#find should not cast single value to array for schematype of Array': function () {
+ var query = new Query();
+ var db = start();
+ var Product = db.model('Product');
+ var Comment = db.model('Comment');
+ db.close();
+
+ var id = new DocumentObjectId;
+ var castedComment = { _id: id, text: 'hello there' };
+ var comment = new Comment(castedComment);
+
+ var params = {
+ array: 5
+ , ids: id
+ , comments: comment
+ , strings: 'Hi there'
+ , numbers: 10000
+ };
+
+ query.cast(Product, params);
+ params.array.should.equal(5);
+ params.ids.should.eql(id);
+ params.comments.should.eql(castedComment);
+ params.strings.should.eql('Hi there');
+ params.numbers.should.eql(10000);
+
+ params.array = [5];
+ params.ids = [id];
+ params.comments = [comment];
+ params.strings = ['Hi there'];
+ params.numbers = [10000];
+ query.cast(Product, params);
+ params.array.should.be.instanceof(Array);
+ params.array[0].should.eql(5);
+ params.ids.should.be.instanceof(Array);
+ params.ids[0].toString().should.eql(id.toString());
+ params.comments.should.be.instanceof(Array);
+ params.comments[0].toObject().should.eql(castedComment);
+ params.strings.should.be.instanceof(Array);
+ params.strings[0].should.eql('Hi there');
+ params.numbers.should.be.instanceof(Array);
+ params.numbers[0].should.eql(10000);
+ },
// Advanced Query options
'test Query#maxscan': function () {
Please sign in to comment.
Something went wrong with that request. Please try again.