Permalink
Browse files

fix regexp validators in node >= v0.6

  • Loading branch information...
1 parent 2d50d64 commit c999522c0084a989c5a95ae009196c4c0d11adad @aheckmann aheckmann committed Feb 9, 2012
Showing with 6 additions and 7 deletions.
  1. +1 −1 lib/schematype.js
  2. +5 −6 test/model.test.js
View
@@ -159,7 +159,7 @@ SchemaType.prototype.get = function (fn) {
*/
SchemaType.prototype.validate = function (obj, error) {
- if ('function' == typeof obj) {
+ if ('function' == typeof obj || obj && 'RegExp' === obj.constructor.name) {
this.validators.push([obj, error]);
return this;
}
View
@@ -1122,16 +1122,15 @@ module.exports = {
// GH-319
'save callback should only execute once regardless of number of failed validations': function () {
- mongoose.model('CallbackFiresOnceValidation', new Schema({
+ var db = start()
+
+ var D = db.model('CallbackFiresOnceValidation', new Schema({
username: { type: String, validate: /^[a-z]{6}$/i }
, email: { type: String, validate: /^[a-z]{6}$/i }
, password: { type: String, validate: /^[a-z]{6}$/i }
}));
- var db = start()
- , CallbackFiresOnceValidation = db.model('CallbackFiresOnceValidation');
-
- var post = new CallbackFiresOnceValidation({
+ var post = new D({
username: "nope"
, email: "too"
, password: "short"
@@ -1140,6 +1139,7 @@ module.exports = {
var timesCalled = 0;
post.save(function (err) {
+ db.close();
err.should.be.an.instanceof(MongooseError);
err.should.be.an.instanceof(ValidationError);
@@ -1161,7 +1161,6 @@ module.exports = {
post.errors.email.message.should.eql('Validator failed for path email');
post.errors.username.message.should.eql('Validator failed for path username');
- db.close();
});
},

0 comments on commit c999522

Please sign in to comment.