Fix the logical operator check

This commit is contained in:
Raymond Feng 2014-06-04 14:23:53 -07:00
parent cdf9956867
commit 5f3c856d2e
2 changed files with 11 additions and 6 deletions

View File

@ -458,8 +458,9 @@ DataAccessObject._coerce = function (where) {
return where; return where;
} }
var err;
if (typeof where !== 'object' || Array.isArray(where)) { if (typeof where !== 'object' || Array.isArray(where)) {
var err = new Error(util.format('The where clause %j is not an object', where)); err = new Error(util.format('The where clause %j is not an object', where));
err.statusCode = 400; err.statusCode = 400;
throw err; throw err;
} }
@ -473,6 +474,10 @@ DataAccessObject._coerce = function (where) {
for (var i = 0; i < clauses.length; i++) { for (var i = 0; i < clauses.length; i++) {
self._coerce(clauses[i]); self._coerce(clauses[i]);
} }
} else {
err = new Error(util.format('The %p operator has invalid clauses %j', p, clauses));
err.statusCode = 400;
throw err;
} }
return where; return where;
} }

View File

@ -1086,7 +1086,7 @@ describe('DataAccessObject', function () {
it('should throw if the where property is not an object', function () { it('should throw if the where property is not an object', function () {
try { try {
// The where clause has to be an object // The where clause has to be an object
error = err;model._coerce('abc'); model._coerce('abc');
} catch (err) { } catch (err) {
error = err; error = err;
} }
@ -1096,7 +1096,7 @@ describe('DataAccessObject', function () {
it('should throw if the where property is an array', function () { it('should throw if the where property is an array', function () {
try { try {
// The where clause cannot be an array // The where clause cannot be an array
error = err;model._coerce([ model._coerce([
{vip: true} {vip: true}
]); ]);
} catch (err) { } catch (err) {
@ -1108,7 +1108,7 @@ describe('DataAccessObject', function () {
it('should throw if the and operator does not take an array', function () { it('should throw if the and operator does not take an array', function () {
try { try {
// The and operator only takes an array of objects // The and operator only takes an array of objects
error = err;model._coerce({and: {x: 1}}); model._coerce({and: {x: 1}});
} catch (err) { } catch (err) {
error = err; error = err;
} }
@ -1118,7 +1118,7 @@ describe('DataAccessObject', function () {
it('should throw if the or operator does not take an array', function () { it('should throw if the or operator does not take an array', function () {
try { try {
// The or operator only takes an array of objects // The or operator only takes an array of objects
error = err;model._coerce({or: {x: 1}}); model._coerce({or: {x: 1}});
} catch (err) { } catch (err) {
error = err; error = err;
} }
@ -1128,7 +1128,7 @@ describe('DataAccessObject', function () {
it('should throw if the or operator does not take an array of objects', function () { it('should throw if the or operator does not take an array of objects', function () {
try { try {
// The or operator only takes an array of objects // The or operator only takes an array of objects
error = err;model._coerce({or: ['x']}); model._coerce({or: ['x']});
} catch(err) { } catch(err) {
error = err; error = err;
} }