diff --git a/lib/ORM.js b/lib/ORM.js index bf6a483a..bcbcfc71 100644 --- a/lib/ORM.js +++ b/lib/ORM.js @@ -134,7 +134,7 @@ exports.connect = function (opts, cb) { db.emit("connect", err, !err ? db : null); }); } catch (ex) { - if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module')) { + if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module') > -1) { return ORM_Error(new ORMError("Connection protocol not supported - have you installed the database driver for " + proto + "?", 'NO_SUPPORT'), cb); } return ORM_Error(ex, cb); diff --git a/test/integration/orm-exports.js b/test/integration/orm-exports.js index 0f20ec08..3b9f1665 100644 --- a/test/integration/orm-exports.js +++ b/test/integration/orm-exports.js @@ -139,6 +139,26 @@ describe("ORM.connect()", function () { }); }); + it("should emit valid error if exception being thrown during connection try", function (done) { + var testConfig = { + protocol : 'mongodb', + href : 'unknownhost', + database : 'unknowndb', + user : '', + password : '' + }, + db = ORM.connect(testConfig); + + db.on("connect", function (err) { + should.exist(err); + should.equal(err.message.indexOf("Connection protocol not supported"), -1); + err.message.should.not.equal("CONNECTION_URL_NO_PROTOCOL"); + err.message.should.not.equal("CONNECTION_URL_EMPTY"); + + return done(); + }); + }); + it("should not modify connection opts", function (done) { var opts = { protocol : 'mysql',