Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 70aea586f4a4a6ed23268c4a125eb94077ec2507 1 parent f84ae70
Brian Noguchi bnoguchi authored
2  Makefile
... ... @@ -1,4 +1,4 @@
1   -EXPRESSO = support/expresso/bin/expresso -I lib --serial
  1 +EXPRESSO = support/expresso/bin/expresso -I lib
2 2
3 3 TESTS = tests/*.test.js
4 4
2  lib/types/email.js
@@ -8,7 +8,7 @@ module.exports.loadType = function (mongoose) {
8 8 function validateEmail (val) {
9 9 return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(val);
10 10 }
11   - this.validate([validateEmail, 'email is invalid']);
  11 + this.validate(validateEmail, 'email is invalid');
12 12 }
13 13 Email.prototype.__proto__ = SchemaTypes.String.prototype;
14 14 Email.prototype.cast = function (val) {
2  lib/types/url.js
@@ -9,7 +9,7 @@ module.exports.loadType = function (mongoose) {
9 9 var urlRegexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
10 10 return urlRegexp.test(val);
11 11 }
12   - this.validate([validateUrl, 'url is invalid']);
  12 + this.validate(validateUrl, 'url is invalid');
13 13 }
14 14 Url.prototype.__proto__ = SchemaTypes.String.prototype;
15 15 Url.prototype.cast = function (val) {
4 package.json
... ... @@ -1,8 +1,8 @@
1 1 { "name": "mongoose-types"
2 2 , "description": "More types for mongoose"
3   -, "version": "1.0.2"
  3 +, "version": "1.0.3"
4 4 , "author": "Brian Noguchi"
5   -, "dependencies": { "mongoose": ">= 1.0.13"}
  5 +, "dependencies": { "mongoose": ">= 1.0.16"}
6 6 , "keywords": [ "mongoose", "mongo", "mongodb", "types" ]
7 7 , "scripts": { "test": "make test" }
8 8 , "engines": { "node": ">= 0.1.101" }
17 tests/email.test.js
@@ -13,35 +13,30 @@ mongoose.model('User', UserSchema);
13 13 var User;
14 14
15 15 module.exports = {
16   - before: function(done){
  16 + before: function(){
17 17 User = db.model('User', UserSchema);
18   - User.remove({}, function (err) {
19   - done();
20   - });
  18 + User.remove({}, function (err) {});
21 19 },
22   - 'test invalid email validation': function (done) {
  20 + 'test invalid email validation': function () {
23 21 var user = new User({email: 'hello'});
24 22 user.save(function (err) {
25   - err.should.equal('email is invalid');
  23 + err.message.should.equal('Validator "email is invalid" failed for path email');
26 24 user.isNew.should.be.true;
27   - done();
28 25 });
29 26 },
30   - 'test valid email validation': function (done) {
  27 + 'test valid email validation': function () {
31 28 var user = new User({ email: 'brian@brian.com' });
32 29 user.save(function (err) {
33 30 err.should.eql(null);
34 31 user.isNew.should.be.false;
35   - done();
36 32 });
37 33 },
38   - 'email should be converted to lowercase': function (done) {
  34 + 'email should be converted to lowercase': function () {
39 35 var user = new User({ email: 'mIxEdCaSe@lowercase.com'});
40 36 user.save(function (err) {
41 37 user.email.should.equal('mixedcase@lowercase.com');
42 38 User.findById(user._id, function (err, refreshed) {
43 39 refreshed.email.should.equal('mixedcase@lowercase.com');
44   - done();
45 40 });
46 41 });
47 42 },
21 tests/url.test.js
@@ -13,46 +13,39 @@ mongoose.model('Webpage', WebpageSchema);
13 13 var Webpage;
14 14
15 15 module.exports = {
16   - before: function(done){
  16 + before: function(){
17 17 Webpage = db.model('Webpage', WebpageSchema);
18   - Webpage.remove({}, function (err) {
19   - done();
20   - });
  18 + Webpage.remove({}, function (err) {});
21 19 },
22   - 'test invalid url validation': function (done) {
  20 + 'test invalid url validation': function () {
23 21 var webpage = new Webpage({url: 'file:///home/'});
24 22 webpage.save(function (err) {
25   - throw err;
26   - err.should.equal('url is invalid');
  23 + err.message.should.equal('Validator "url is invalid" failed for path url');
27 24 webpage.isNew.should.be.true;
28   - done();
29 25 });
30 26 },
31   - 'test valid url validation': function (done) {
  27 + 'test valid url validation': function () {
32 28 var webpage = new Webpage({ url: 'http://www.google.com/' });
33 29 webpage.save(function (err) {
34 30 err.should.eql(null);
35 31 webpage.isNew.should.be.false;
36   - done();
37 32 });
38 33 },
39   - 'url normalization should remove www.': function (done) {
  34 + 'url normalization should remove www.': function () {
40 35 var webpage = new Webpage({ url: 'http://www.google.com/'});
41 36 webpage.save(function (err) {
42 37 webpage.url.should.equal('http://google.com/');
43 38 Webpage.findById(webpage._id, function (err, refreshed) {
44 39 refreshed.url.should.equal('http://google.com/');
45   - done();
46 40 });
47 41 });
48 42 },
49   - 'url normalization should add a trailing slash': function (done) {
  43 + 'url normalization should add a trailing slash': function () {
50 44 var webpage = new Webpage({ url: 'http://google.com'});
51 45 webpage.save(function (err) {
52 46 webpage.url.should.equal('http://google.com/');
53 47 Webpage.findById(webpage._id, function (err, refreshed) {
54 48 refreshed.url.should.equal('http://google.com/');
55   - done();
56 49 });
57 50 });
58 51 },

0 comments on commit 70aea58

Please sign in to comment.
Something went wrong with that request. Please try again.