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 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/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..c91ca48 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; }); }, @@ -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(); } 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(){