Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Should not return error when property of type array is set to object … #1428

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ function List(items, itemType, parent) {

items = items || [];
if (!Array.isArray(items)) {
const err = new Error(g.f('Items must be an array: %j', items));
err.statusCode = 400;
throw err;
try {
items = Object.keys(items).map(key => items[key]);
} catch (e) {
var err = new Error(util.format('Items must be an array or object: %j. Error: %j', items, e));
err.statusCode = 400;
throw err;
}
}

if (!itemType) {
Expand Down
6 changes: 3 additions & 3 deletions test/datatype.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ describe('datatypes', function() {
done();
});

it('should return 400 when property of type array is set to object value',
it('should not return error when property of type array is set to object value',
function(done) {
var myModel = db.define('myModel', {
list: {type: ['object']},
});

(function() {
myModel.create({list: {key: 'This string will crash the server'}});
}).should.throw({statusCode: 400});
myModel.create({list: {key: 'This string wont crash the server'}});
}).should.not.throw({statusCode: 400});

done();
});
Expand Down