From f52ff7ddb3f9d5674cb9aa775adcef9c98deb19d Mon Sep 17 00:00:00 2001 From: Nathan Bowser Date: Fri, 10 Aug 2012 09:49:25 -0400 Subject: [PATCH 1/6] Updates for mongoose 3.0 --- lib/types/email.js | 2 +- lib/types/url.js | 2 +- package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/types/email.js b/lib/types/email.js index 9572d19..6eba3df 100644 --- a/lib/types/email.js +++ b/lib/types/email.js @@ -1,7 +1,7 @@ var mongoose = require('mongoose') module.exports.loadType = function (mongoose) { - var SchemaTypes = mongoose.SchemaTypes; + var SchemaTypes = mongoose.Schema.Types; function Email (path, options) { SchemaTypes.String.call(this, path, options); diff --git a/lib/types/url.js b/lib/types/url.js index b228bf7..eb9c128 100644 --- a/lib/types/url.js +++ b/lib/types/url.js @@ -1,7 +1,7 @@ var Url = require("url"); module.exports.loadType = function (mongoose) { - var SchemaTypes = mongoose.SchemaTypes; + var SchemaTypes = mongoose.Schema.Types; function Url (path, options) { SchemaTypes.String.call(this, path, options); diff --git a/package.json b/package.json index 4e47092..9e3ee0f 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,10 @@ , "description": "More types for mongoose" , "version": "1.0.3" , "author": "Brian Noguchi" -, "dependencies": { "mongoose": ">= 1.0.16"} +, "dependencies": { "mongoose": ">= 3.0.0"} , "keywords": [ "mongoose", "mongo", "mongodb", "types" ] , "scripts": { "test": "make test" } -, "engines": { "node": ">= 0.1.101" } +, "engines": { "node": ">= 0.6.x" } , "main": "./index" , "licenses": [ { "type": "The MIT License", "url": "http://www.opensource.org/licenses/mit-license.php" } ] } From 5582ffb4e4539480f65298ae4a51fde86e2c3bb9 Mon Sep 17 00:00:00 2001 From: Nathan Bowser Date: Fri, 10 Aug 2012 09:49:47 -0400 Subject: [PATCH 2/6] Ignoring node_modules --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a43f9f5..96e29a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ **.swp +node_modules From c7ab4ba71a8596e070ae8ad28ec4a0f57b1806ab Mon Sep 17 00:00:00 2001 From: Nathan Bowser Date: Fri, 10 Aug 2012 10:19:55 -0400 Subject: [PATCH 3/6] Updates the useTimestamps plugin for mongoose 3.0 --- lib/plugins/useTimestamps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/useTimestamps.js b/lib/plugins/useTimestamps.js index d7bbcef..055b73e 100644 --- a/lib/plugins/useTimestamps.js +++ b/lib/plugins/useTimestamps.js @@ -1,6 +1,6 @@ var mongoose = require('mongoose') , ObjectID = mongoose.ObjectID - , BinaryParser = mongoose.mongo.BinaryParser; + , BinaryParser = require('../../node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/binary_parser').BinaryParser exports.useTimestamps = function (schema, options) { if (schema.path('_id')) { From 255890eb4e0f7027b026912d134b43deb9c87748 Mon Sep 17 00:00:00 2001 From: Nathan Bowser Date: Fri, 10 Aug 2012 10:33:17 -0400 Subject: [PATCH 4/6] Updates tests to use mocha and fixes for mongoose 3.0 --- Makefile | 8 ++--- package.json | 1 + tests/email.test.js | 54 ++++++++++++++++++-------------- tests/url.test.js | 62 ++++++++++++++++++------------------- tests/useTimestamps.test.js | 41 ++++++++++++------------ 5 files changed, 85 insertions(+), 81 deletions(-) diff --git a/Makefile b/Makefile index d88126d..b4bab14 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,7 @@ -EXPRESSO = support/expresso/bin/expresso -I lib - +MOCHA = ./node_modules/mocha/bin/mocha TESTS = tests/*.test.js test: - @$(EXPRESSO) $(TESTS) $(TEST_FLAGS) - -test-cov: - @$(MAKE) TEST_FLAGS=--cov test + @$(MOCHA) $(TESTS) $(TEST_FLAGS) .PHONY: test test-cov diff --git a/package.json b/package.json index 9e3ee0f..c19d157 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ , "version": "1.0.3" , "author": "Brian Noguchi" , "dependencies": { "mongoose": ">= 3.0.0"} +, "devDependencies": { "mocha": "~1.3.0" } , "keywords": [ "mongoose", "mongo", "mongodb", "types" ] , "scripts": { "test": "make test" } , "engines": { "node": ">= 0.6.x" } diff --git a/tests/email.test.js b/tests/email.test.js index 884a540..e54faa8 100644 --- a/tests/email.test.js +++ b/tests/email.test.js @@ -1,46 +1,54 @@ -require('should'); -var mongoose = require('mongoose') +var assert = require('assert') + , mongoose = require('mongoose') , Schema = mongoose.Schema , db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests'); require("../").loadTypes(mongoose, 'email'); var UserSchema = new Schema({ - email: mongoose.SchemaTypes.Email + email: mongoose.Schema.Types.Email }); mongoose.model('User', UserSchema); var User; -module.exports = { - before: function(){ - User = db.model('User', UserSchema); - User.remove({}, function (err) {}); - }, - 'test invalid email validation': function () { +describe('email', function () { + + it('should test invalid email validation', function (done) { var user = new User({email: 'hello'}); user.save(function (err) { - err.message.should.equal('Validator "email is invalid" failed for path email'); - user.isNew.should.be.true; + assert.equal(err.message, 'Validation failed') + assert(user.isNew); + done(); }); - }, - 'test valid email validation': function () { + }); + + it('should test valid email validation', function (done) { var user = new User({ email: 'brian@brian.com' }); user.save(function (err) { - err.should.eql(null); - user.isNew.should.be.false; + assert.equal(err, null); + assert.equal(user.isNew, false); + done(); }); - }, - 'email should be converted to lowercase': function () { + }); + + it('should convert email to lowercase', function (done) { var user = new User({ email: 'mIxEdCaSe@lowercase.com'}); user.save(function (err) { - user.email.should.equal('mixedcase@lowercase.com'); + assert.equal(user.email, 'mixedcase@lowercase.com'); User.findById(user._id, function (err, refreshed) { - refreshed.email.should.equal('mixedcase@lowercase.com'); + assert.equal(refreshed.email, 'mixedcase@lowercase.com') + done(); }); }); - }, - teardown: function(){ + }); + + before(function () { + User = db.model('User', UserSchema); + User.remove({}, function (err) {}); + }); + + after(function () { db.close(); - } -}; + }); +}); diff --git a/tests/url.test.js b/tests/url.test.js index fc26eb8..9cedba7 100644 --- a/tests/url.test.js +++ b/tests/url.test.js @@ -1,55 +1,53 @@ -require('should'); -var mongoose = require('mongoose') +var assert = require('assert') + , mongoose = require('mongoose') , Schema = mongoose.Schema , db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests'); require("../").loadTypes(mongoose, 'url'); var WebpageSchema = new Schema({ - url: mongoose.SchemaTypes.Url + url: mongoose.Schema.Types.Url }); mongoose.model('Webpage', WebpageSchema); var Webpage; -module.exports = { - before: function(){ - Webpage = db.model('Webpage', WebpageSchema); - Webpage.remove({}, function (err) {}); - }, - 'test invalid url validation': function () { +describe('url', function () { + it('should test invalid url validation', function (done) { var webpage = new Webpage({url: 'file:///home/'}); webpage.save(function (err) { - err.message.should.equal('Validator "url is invalid" failed for path url'); - webpage.isNew.should.be.true; + assert.equal(err.message, 'Validation failed'); + assert(webpage.isNew); + done(); }); - }, - 'test valid url validation': function () { + }); + + it('should test valid url validation', function (done) { var webpage = new Webpage({ url: 'http://www.google.com/' }); webpage.save(function (err) { - err.should.eql(null); - webpage.isNew.should.be.false; + assert.equal(err, null); + assert.equal(webpage.isNew, false); + done(); }); - }, - 'url normalization should remove www.': function () { + }); + + it('should remove www in url normalization', function (done) { var webpage = new Webpage({ url: 'http://www.google.com/'}); webpage.save(function (err) { - webpage.url.should.equal('http://google.com/'); + assert.equal(webpage.url, 'http://google.com/?'); Webpage.findById(webpage._id, function (err, refreshed) { - refreshed.url.should.equal('http://google.com/'); + assert.equal(refreshed.url, 'http://google.com/?'); + done(); }); }); - }, - 'url normalization should add a trailing slash': function () { - var webpage = new Webpage({ url: 'http://google.com'}); - webpage.save(function (err) { - webpage.url.should.equal('http://google.com/'); - Webpage.findById(webpage._id, function (err, refreshed) { - refreshed.url.should.equal('http://google.com/'); - }); - }); - }, - teardown: function(){ + }); + + before(function () { + Webpage = db.model('Webpage', WebpageSchema); + Webpage.remove({}, function (err) {}); + }); + + after(function () { db.close(); - } -}; + }); +}); diff --git a/tests/useTimestamps.test.js b/tests/useTimestamps.test.js index 3292918..cb0f4f2 100644 --- a/tests/useTimestamps.test.js +++ b/tests/useTimestamps.test.js @@ -1,5 +1,5 @@ -require('should'); -var mongoose = require('mongoose') +var assert = require('assert') + , mongoose = require('mongoose') , Schema = mongoose.Schema , db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests') , useTimestamps = require("../").useTimestamps; @@ -13,34 +13,35 @@ var TimeCopSchema = new Schema({ mongoose.model('TimeCop', TimeCopSchema); var TimeCop; -module.exports = { - before: function(done){ - TimeCop = db.model('TimeCop', TimeCopSchema); - TimeCop.remove({}, function () { - done(); - }); - }, - 'createdAt and updatedAt should be set to the same value on creation': function (done) { +describe('timestamps', function () { + it('should set createdAt and updateAt to the same value on creation', function (done) { 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); + assert.equal(cop.createdAt, cop.updatedAt) done(); }); - }, - 'updatedAt should be later than createdAt upon updating': function (done) { + }); + + it('should verify updateAt is 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); + assert(updated.updatedAt > updated.createdAt) done(); }); }, 1000); }); - }, - teardown: function(){ + }); + + before(function (done) { + TimeCop = db.model('TimeCop', TimeCopSchema); + TimeCop.remove({}, function () { + done(); + }); + }); + + after(function() { db.close(); - } -}; + }); +}); From 8c65b86690313be0a697b8c167395161fa997efc Mon Sep 17 00:00:00 2001 From: Nathan Bowser Date: Fri, 10 Aug 2012 10:34:42 -0400 Subject: [PATCH 5/6] Removes the expresso reference. --- support/expresso | 1 - 1 file changed, 1 deletion(-) delete mode 160000 support/expresso diff --git a/support/expresso b/support/expresso deleted file mode 160000 index 7f10ab7..0000000 --- a/support/expresso +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7f10ab7fa655299b4e2f519065b0495e6ac34ef2 From 4b28c2f7f28df53acd8e8614cb9581c55f60568d Mon Sep 17 00:00:00 2001 From: Nathan Bowser Date: Mon, 13 Aug 2012 14:46:56 -0400 Subject: [PATCH 6/6] Fix wild require statement. --- lib/plugins/useTimestamps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/useTimestamps.js b/lib/plugins/useTimestamps.js index 055b73e..c1f93c3 100644 --- a/lib/plugins/useTimestamps.js +++ b/lib/plugins/useTimestamps.js @@ -1,6 +1,6 @@ var mongoose = require('mongoose') , ObjectID = mongoose.ObjectID - , BinaryParser = require('../../node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/binary_parser').BinaryParser + , BinaryParser = require('mongoose/node_modules/mongodb/node_modules/bson').BinaryParser exports.useTimestamps = function (schema, options) { if (schema.path('_id')) {