Skip to content

Commit

Permalink
Fix validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Apr 1, 2013
1 parent 3499317 commit b0a1ed3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/model.js
Expand Up @@ -199,6 +199,7 @@ AbstractClass.create = function (data, callback) {
}
}


var obj;
// if we come from save
if (data instanceof Model && !data.id) {
Expand Down
6 changes: 1 addition & 5 deletions lib/validations.js
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions test/validations.test.js
Expand Up @@ -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;
Expand All @@ -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();
});
});
});

});
});

Expand Down

0 comments on commit b0a1ed3

Please sign in to comment.