From bdefcbbd8f0fc7964a7ab76331c3012906bf24af Mon Sep 17 00:00:00 2001 From: Eddie Ringle Date: Sun, 25 Sep 2011 23:01:30 -0400 Subject: [PATCH 1/3] Fix tests Signed-off-by: Eddie Ringle --- tests/email.test.js | 6 +++--- tests/url.test.js | 6 +++--- tests/useTimestamps.test.js | 33 ++++++++++++++++----------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tests/email.test.js b/tests/email.test.js index 884a540..8323612 100644 --- a/tests/email.test.js +++ b/tests/email.test.js @@ -1,4 +1,4 @@ -require('should'); +var should = require('should'); var mongoose = require('mongoose') , Schema = mongoose.Schema , db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests'); @@ -20,14 +20,14 @@ module.exports = { 'test invalid email validation': function () { var user = new User({email: 'hello'}); user.save(function (err) { - err.message.should.equal('Validator "email is invalid" failed for path email'); + err.errors.email.message.should.equal('Validator "email is invalid" failed for path email'); user.isNew.should.be.true; }); }, 'test valid email validation': function () { var user = new User({ email: 'brian@brian.com' }); user.save(function (err) { - err.should.eql(null); + should.not.exist(err); user.isNew.should.be.false; }); }, diff --git a/tests/url.test.js b/tests/url.test.js index fc26eb8..c475daf 100644 --- a/tests/url.test.js +++ b/tests/url.test.js @@ -1,4 +1,4 @@ -require('should'); +var should = require('should'); var mongoose = require('mongoose') , Schema = mongoose.Schema , db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests'); @@ -20,14 +20,14 @@ module.exports = { 'test invalid url validation': function () { var webpage = new Webpage({url: 'file:///home/'}); webpage.save(function (err) { - err.message.should.equal('Validator "url is invalid" failed for path url'); + err.errors.url.message.should.equal('Validator "url is invalid" failed for path url'); webpage.isNew.should.be.true; }); }, 'test valid url validation': function () { var webpage = new Webpage({ url: 'http://www.google.com/' }); webpage.save(function (err) { - err.should.eql(null); + should.not.exist(err); webpage.isNew.should.be.false; }); }, diff --git a/tests/useTimestamps.test.js b/tests/useTimestamps.test.js index 3292918..271841f 100644 --- a/tests/useTimestamps.test.js +++ b/tests/useTimestamps.test.js @@ -1,4 +1,4 @@ -require('should'); +var should = require('should'); var mongoose = require('mongoose') , Schema = mongoose.Schema , db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests') @@ -14,30 +14,29 @@ mongoose.model('TimeCop', TimeCopSchema); var TimeCop; module.exports = { - before: function(done){ + before: function(){ TimeCop = db.model('TimeCop', TimeCopSchema); - TimeCop.remove({}, function () { - done(); - }); + TimeCop.remove({}, function () {}); }, - 'createdAt and updatedAt should be set to the same value on creation': function (done) { + 'createdAt and updatedAt should be set to the same value on creation': function () { var cop = new TimeCop({ email: 'brian@brian.com' }); cop.save( function (err) { cop.createdAt.should.be.an.instanceof(Date); cop.updatedAt.should.be.an.instanceof(Date); - done(); }); }, - 'updatedAt should be later than createdAt upon updating': function (done) { - TimeCop.findOne({email: 'brian@brian.com'}, function (err, found) { - found.email = 'jeanclaude@vandamme.com'; - setTimeout( function () { - found.save( function (err, updated) { - updated.updatedAt.should.be.greater.than(updated.createdAt); - assert.ok(updated.updatedAt > updated.createdAt); - done(); - }); - }, 1000); + 'updatedAt should be later than createdAt upon updating': function () { + var cop = new TimeCop({ email: 'brain@brain.com' }); + cop.save( function (err) { + should.not.exist(err); + TimeCop.findOne({email: 'brian@brian.com'}, function (err, found) { + found.email = 'jeanclaude@vandamme.com'; + setTimeout( function () { + found.save( function (err, updated) { + updated.updatedAt.should.be.above(updated.createdAt); + }); + }, 500); + }); }); }, teardown: function(){ From 1cf185ae13196f9e4089c2afbf28d5008a8e8dad Mon Sep 17 00:00:00 2001 From: Eddie Ringle Date: Sun, 25 Sep 2011 23:01:52 -0400 Subject: [PATCH 2/3] Url normalization: strip trailing '?' when querystring is empty Signed-off-by: Eddie Ringle --- lib/types/url.js | 4 ++-- tests/url.test.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/types/url.js b/lib/types/url.js index b228bf7..392e76b 100644 --- a/lib/types/url.js +++ b/lib/types/url.js @@ -37,7 +37,7 @@ module.exports.normalizeUrl = (function () { }; return function (uri) { - var parsedUrl = Url.parse(uri, true) + var parsedUrl = Url.parse(uri) , urlstr = "" , protocol = parsedUrl.protocol , hostname = parsedUrl.hostname @@ -50,7 +50,7 @@ module.exports.normalizeUrl = (function () { "/" // Add trailing / ); if (query) { - urlstr += "?" + reorderQuery(query); + urlstr += "?" + reorderQuery(Url.parse(uri, true).query); } if (hash) { urlstr += hash; diff --git a/tests/url.test.js b/tests/url.test.js index c475daf..c91ca48 100644 --- a/tests/url.test.js +++ b/tests/url.test.js @@ -49,6 +49,15 @@ module.exports = { }); }); }, + 'url normalization should prevent trailing "?"': function () { + var webpage = new Webpage({ url: 'http://google.com/maps'}); + webpage.save(function (err) { + webpage.url.should.equal('http://google.com/maps'); + Webpage.findById(webpage._id, function (err, refreshed) { + refreshed.url.should.equal('http://google.com/maps'); + }); + }); + }, teardown: function(){ db.close(); } From 8bdb65f2c62c69e090946ed08fedd5c8a3b7981a Mon Sep 17 00:00:00 2001 From: Eddie Ringle Date: Sun, 25 Sep 2011 23:10:41 -0400 Subject: [PATCH 3/3] Run tests in serial mode again Test suite will hang if run in parallel mode due to the mongodb connection remaining open. Of course, this will also hang the test suite due to a bug in expresso, see https://github.com/visionmedia/expresso/pull/128 Signed-off-by: Eddie Ringle --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d88126d..7066043 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -EXPRESSO = support/expresso/bin/expresso -I lib +EXPRESSO = support/expresso/bin/expresso -I lib --serial TESTS = tests/*.test.js