Skip to content
Merged
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
4 changes: 3 additions & 1 deletion lib/Drivers/DML/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ Driver.prototype.propertyToValue = function (value, property) {
value = (value) ? 1 : 0;
break;
case "object":
value = JSON.stringify(value);
if (value !== null) {
value = JSON.stringify(value);
}
break;
case "point":
return function() { return 'POINT(' + value.x + ', ' + value.y + ')'; };
Expand Down
2 changes: 1 addition & 1 deletion lib/Drivers/DML/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Driver.prototype.propertyToValue = function (value, property) {

switch (property.type) {
case "object":
if (!Buffer.isBuffer(value)) {
if (value !== null && !Buffer.isBuffer(value)) {
value = new Buffer(JSON.stringify(value));
}
break;
Expand Down
4 changes: 3 additions & 1 deletion lib/Drivers/DML/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ Driver.prototype.propertyToValue = function (value, property) {
value = (value) ? 1 : 0;
break;
case "object":
value = JSON.stringify(value);
if (value !== null) {
value = JSON.stringify(value);
}
break;
case "date":
if (this.config.query && this.config.query.strdates) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"async" : "*",
"mocha" : "1.13.0",
"should" : "1.2.2",
"mongodb" : "1.3.19"
"mongodb" : "1.3.19",
"glob" : "3.2.8"
},
"optionalDependencies": {}
}
130 changes: 130 additions & 0 deletions test/integration/drivers/postgres_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
var _ = require('lodash');
var should = require('should');
var Driver = require('../../../lib/Drivers/DML/postgres').Driver;
var helper = require('../../support/spec_helper');
var common = require('../../common');

if (common.protocol() == "mongodb") return;

describe("Postgres driver", function() {
describe("#propertyToValue", function () {
describe("type object", function () {
function evaluate (input) {
var driver = new Driver({}, {}, {});
return driver.propertyToValue(input, { type: 'object' });
}

it("should not change null", function () {
should.strictEqual(evaluate(null), null);
});

it("should not change buffer", function () {
var b = new Buffer('abc');
should.strictEqual(evaluate(b), b);
});

it("should encode everything else as a Buffer", function () {
var input = { abc: 123 };
var out = evaluate(input);

should(out instanceof Buffer);
should.equal(JSON.stringify(input), out.toString());
});
});

describe("date", function () {
function evaluate (input, opts) {
if (!opts) opts = {};
var driver = new Driver(opts.config, {}, {});
return driver.propertyToValue(input, { type: 'date' });
}

it("should do nothing when timezone isn't configured", function () {
var input = new Date();
var inputStr = input.toString();
var out = evaluate(input);

should.strictEqual(input, out);
should.equal(inputStr, out.toString());
});

// I'm not sure if the timezone tests are right
it("should offset time by specified timezone amount for + timezones", function () {
var input = new Date(Date.UTC(2014,2,5,13,14,0,0));
var inputStr = input.toUTCString();
var out = evaluate(input, { config: { timezone: '+06:11' } });

should.equal(out.toUTCString(), 'Wed, 05 Mar 2014 08:25:00 GMT');
});

// The HH:mm for this one seem odd
it("should offset time by specified timezone amount for + timezones", function () {
var input = new Date(Date.UTC(2014,2,5,13,14,0,0));
var inputStr = input.toUTCString();
var out = evaluate(input, { config: { timezone: '-06:11' } });

should.equal(out.toUTCString(), 'Tue, 04 Mar 2014 20:03:00 GMT');
});
// --------------
});

describe("type point", function () {
function evaluate (input) {
var driver = new Driver({}, {}, {});
return driver.propertyToValue(input, { type: 'point' });
}

it("should encode correctly", function () {
var out = evaluate({ x: 5, y: 7 });

should(out instanceof Function);
should.equal(out(), "POINT(5, 7)");
});
});

describe("custom type", function () {
var customType = {
propertyToValue: function (input) {
return input + ' QWERTY';
}
};

function evaluate (input, customTypes) {
var driver = new Driver({}, {}, {});
if (customType) {
for (var k in customTypes) {
driver.customTypes[k] = customTypes[k];
}
}
return driver.propertyToValue(input, { type: 'qwerty' });
}

it("should do custom type conversion if provided", function () {
var opts = { qwerty: customType };
var out = evaluate('f', opts);

should.equal(out, 'f QWERTY');
});

it("should not do custom type conversion if not provided", function () {
var opts = { qwerty: {} };
var out = evaluate('f', opts);

should.equal(out, 'f');
});
});

it("should do nothing for other types", function () {
function evaluate (input, type) {
var driver = new Driver({}, {}, {});
return driver.propertyToValue(input, { type: type });
}

should.strictEqual(evaluate('abc', { type: 'string' }), 'abc');
should.strictEqual(evaluate(42, { type: 'number' }), 42);
should.strictEqual(evaluate(undefined, { type: 'bleh' }), undefined);
});

});

});
19 changes: 7 additions & 12 deletions test/run.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Mocha = require("mocha");
var fs = require("fs");
var glob = require("glob");
var path = require("path");
var common = require("./common");
var logging = require("./logging");
var location = path.normalize(path.join(__dirname, "integration"));
var location = path.normalize(path.join(__dirname, "integration", "**", "*.js"));
var mocha = new Mocha({
reporter: "progress"
});
Expand All @@ -20,14 +20,9 @@ switch (common.hasConfig(common.protocol())) {
runTests();

function runTests() {
fs.readdirSync(location).filter(function (file) {
return file.substr(-3) === '.js';
}).forEach(function (file) {
glob.sync(location).forEach(function (file) {
if (!shouldRunTest(file)) return;

mocha.addFile(
path.join(location, file)
);
mocha.addFile(file);
});

logging.info("Testing **%s**", common.getConnectionString());
Expand All @@ -38,11 +33,11 @@ function runTests() {
}

function shouldRunTest(file) {
var name = file.substr(0, file.length - 3);
var name = path.basename(file).slice(0, -3)
var proto = common.protocol();
var exclude = ['model-aggregate','property-number-size','smart-types'];

if (proto == "mongodb" && [ "model-aggregate",
"property-number-size", "smart-types" ].indexOf(name) >= 0) return false;
if (proto == "mongodb" && exclude.indexOf(name) >= 0) return false;

return true;
}