Fix validation issue

This commit is contained in:
Anatoliy Chakkaev 2013-04-01 20:08:22 +04:00
parent 349931780a
commit b0a1ed3bed
3 changed files with 19 additions and 5 deletions

View File

@ -199,6 +199,7 @@ AbstractClass.create = function (data, callback) {
} }
} }
var obj; var obj;
// if we come from save // if we come from save
if (data instanceof Model && !data.id) { if (data instanceof Model && !data.id) {

View File

@ -396,11 +396,7 @@ Validatable.prototype.isValid = function (callback, data) {
}, data); }, data);
if (!async) { if (async) {
if (valid) cleanErrors(this);
if (callback) callback(valid);
return valid;
} else {
// in case of async validation we should return undefined here, // in case of async validation we should return undefined here,
// because not all validations are finished yet // because not all validations are finished yet
return; return;

View File

@ -47,6 +47,7 @@ describe('validations', function() {
describe('commons', function() { describe('commons', function() {
describe('skipping', function() { describe('skipping', function() {
it('should allow to skip using if: attribute', function() { it('should allow to skip using if: attribute', function() {
User.validatesPresenceOf('pendingPeriod', {if: 'createdByAdmin'}); User.validatesPresenceOf('pendingPeriod', {if: 'createdByAdmin'});
var user = new User; var user = new User;
@ -56,6 +57,22 @@ describe('validations', function() {
user.pendingPeriod = 1 user.pendingPeriod = 1
user.isValid().should.be.true; 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();
});
});
});
}); });
}); });