Permalink
Browse files

Added validation fixes (thanks Lenin). And also made tests run in par…

…allel (before was serial). Version bump to v1.0.3
  • Loading branch information...
1 parent f84ae70 commit 70aea586f4a4a6ed23268c4a125eb94077ec2507 @bnoguchi bnoguchi committed Feb 24, 2011
Showing with 18 additions and 30 deletions.
  1. +1 −1 Makefile
  2. +1 −1 lib/types/email.js
  3. +1 −1 lib/types/url.js
  4. +2 −2 package.json
  5. +6 −11 tests/email.test.js
  6. +7 −14 tests/url.test.js
View
2 Makefile
@@ -1,4 +1,4 @@
-EXPRESSO = support/expresso/bin/expresso -I lib --serial
+EXPRESSO = support/expresso/bin/expresso -I lib
TESTS = tests/*.test.js
View
2 lib/types/email.js
@@ -8,7 +8,7 @@ module.exports.loadType = function (mongoose) {
function validateEmail (val) {
return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(val);
}
- this.validate([validateEmail, 'email is invalid']);
+ this.validate(validateEmail, 'email is invalid');
}
Email.prototype.__proto__ = SchemaTypes.String.prototype;
Email.prototype.cast = function (val) {
View
2 lib/types/url.js
@@ -9,7 +9,7 @@ module.exports.loadType = function (mongoose) {
var urlRegexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
return urlRegexp.test(val);
}
- this.validate([validateUrl, 'url is invalid']);
+ this.validate(validateUrl, 'url is invalid');
}
Url.prototype.__proto__ = SchemaTypes.String.prototype;
Url.prototype.cast = function (val) {
View
4 package.json
@@ -1,8 +1,8 @@
{ "name": "mongoose-types"
, "description": "More types for mongoose"
-, "version": "1.0.2"
+, "version": "1.0.3"
, "author": "Brian Noguchi"
-, "dependencies": { "mongoose": ">= 1.0.13"}
+, "dependencies": { "mongoose": ">= 1.0.16"}
, "keywords": [ "mongoose", "mongo", "mongodb", "types" ]
, "scripts": { "test": "make test" }
, "engines": { "node": ">= 0.1.101" }
View
17 tests/email.test.js
@@ -13,35 +13,30 @@ mongoose.model('User', UserSchema);
var User;
module.exports = {
- before: function(done){
+ before: function(){
User = db.model('User', UserSchema);
- User.remove({}, function (err) {
- done();
- });
+ User.remove({}, function (err) {});
},
- 'test invalid email validation': function (done) {
+ 'test invalid email validation': function () {
var user = new User({email: 'hello'});
user.save(function (err) {
- err.should.equal('email is invalid');
+ err.message.should.equal('Validator "email is invalid" failed for path email');
user.isNew.should.be.true;
- done();
});
},
- 'test valid email validation': function (done) {
+ 'test valid email validation': function () {
var user = new User({ email: 'brian@brian.com' });
user.save(function (err) {
err.should.eql(null);
user.isNew.should.be.false;
- done();
});
},
- 'email should be converted to lowercase': function (done) {
+ 'email should be converted to lowercase': function () {
var user = new User({ email: 'mIxEdCaSe@lowercase.com'});
user.save(function (err) {
user.email.should.equal('mixedcase@lowercase.com');
User.findById(user._id, function (err, refreshed) {
refreshed.email.should.equal('mixedcase@lowercase.com');
- done();
});
});
},
View
21 tests/url.test.js
@@ -13,46 +13,39 @@ mongoose.model('Webpage', WebpageSchema);
var Webpage;
module.exports = {
- before: function(done){
+ before: function(){
Webpage = db.model('Webpage', WebpageSchema);
- Webpage.remove({}, function (err) {
- done();
- });
+ Webpage.remove({}, function (err) {});
},
- 'test invalid url validation': function (done) {
+ 'test invalid url validation': function () {
var webpage = new Webpage({url: 'file:///home/'});
webpage.save(function (err) {
- throw err;
- err.should.equal('url is invalid');
+ err.message.should.equal('Validator "url is invalid" failed for path url');
webpage.isNew.should.be.true;
- done();
});
},
- 'test valid url validation': function (done) {
+ 'test valid url validation': function () {
var webpage = new Webpage({ url: 'http://www.google.com/' });
webpage.save(function (err) {
err.should.eql(null);
webpage.isNew.should.be.false;
- done();
});
},
- 'url normalization should remove www.': function (done) {
+ 'url normalization should remove www.': function () {
var webpage = new Webpage({ url: 'http://www.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/');
- done();
});
});
},
- 'url normalization should add a trailing slash': function (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/');
- done();
});
});
},

0 comments on commit 70aea58

Please sign in to comment.