Skip to content
Browse files

Fix validation issue

  • Loading branch information...
1 parent 3499317 commit b0a1ed3bed3ce87927c1dc428ee7b74a7892f253 @1602 committed Apr 1, 2013
Showing with 19 additions and 5 deletions.
  1. +1 −0 lib/model.js
  2. +1 −5 lib/validations.js
  3. +17 −0 test/validations.test.js
View
1 lib/model.js
@@ -199,6 +199,7 @@ AbstractClass.create = function (data, callback) {
}
}
+
var obj;
// if we come from save
if (data instanceof Model && !data.id) {
View
6 lib/validations.js
@@ -396,11 +396,7 @@ Validatable.prototype.isValid = function (callback, data) {
}, data);
- if (!async) {
- if (valid) cleanErrors(this);
- if (callback) callback(valid);
- return valid;
- } else {
+ if (async) {
// in case of async validation we should return undefined here,
// because not all validations are finished yet
return;
View
17 test/validations.test.js
@@ -47,6 +47,7 @@ describe('validations', function() {
describe('commons', function() {
describe('skipping', function() {
+
it('should allow to skip using if: attribute', function() {
User.validatesPresenceOf('pendingPeriod', {if: 'createdByAdmin'});
var user = new User;
@@ -56,6 +57,22 @@ describe('validations', function() {
user.pendingPeriod = 1
user.isValid().should.be.true;
});
+
+ });
+
+ describe.only('lifecycle', function() {
+
+ it('should work on create', function(done) {
+ User.validatesPresenceOf('name');
+ User.create(function(e) {
+ should.exist(e);
+ User.create({name: 'Valid'}, function(e, d) {
+ should.not.exist(e);
+ done();
+ });
+ });
+ });
+
});
});

0 comments on commit b0a1ed3

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