不要怂,就是干,撸起袖子干!

Commit c18a7f36 by Sascha Depold

Merge pull request #404 from watson/where-bug

Fix bug in Utils.format that ignore falsy values
2 parents b78ad765 b1235d3b
Showing with 13 additions and 4 deletions
......@@ -47,10 +47,7 @@ var Utils = module.exports = {
return connection.escape(s).replace(/\\"/g, '"')
},
format: function(arr) {
var query = arr[0]
, replacements = Utils._.compact(arr.map(function(obj) { return obj != query ? obj : null}))
return connection.format.apply(connection, [query, replacements])
return connection.format.apply(connection, [arr.shift(), arr])
},
isHash: function(obj) {
return Utils._.isObject(obj) && !Utils._.isArray(obj);
......
......@@ -112,4 +112,16 @@ describe('Utils', function() {
expect(Utils.isHash(values)).toBeTruthy();
});
});
describe('format', function() {
it('should format where clause correctly when the value is truthy', function() {
var where = ['foo = ?', 1];
expect(Utils.format(where)).toEqual('foo = 1');
});
it('should format where clause correctly when the value is falsy', function() {
var where = ['foo = ?', 0];
expect(Utils.format(where)).toEqual('foo = 0');
});
});
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!