diff --git a/lib/utils.js b/lib/utils.js index 3522c101..2c20a77d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -68,7 +68,7 @@ function prepareObject(val, seen) { } seen.push(val); - return prepareValue(val.toPostgres(), seen); + return prepareValue(val.toPostgres(prepareValue), seen); } return JSON.stringify(val); } diff --git a/test/unit/utils-tests.js b/test/unit/utils-tests.js index ecf34475..116dfdd1 100644 --- a/test/unit/utils-tests.js +++ b/test/unit/utils-tests.js @@ -141,6 +141,18 @@ test('prepareValue: objects with complex toPostgres prepared properly', function assert.strictEqual(out, '{"1","2"}'); }); +test('prepareValue: objects with toPostgres receive prepareValue', function() { + var customRange = { + lower: { toPostgres: function() { return 5; } }, + upper: { toPostgres: function() { return 10; } }, + toPostgres: function(prepare) { + return "[" + prepare(this.lower) + "," + prepare(this.upper) + "]"; + } + }; + var out = utils.prepareValue(customRange); + assert.strictEqual(out, "[5,10]"); +}); + test('prepareValue: objects with circular toPostgres rejected', function() { var buf = new Buffer("zomgcustom!"); var customType = {