More fixes/tests
This commit is contained in:
parent
aebf5e9e6b
commit
fafe51833b
|
@ -172,6 +172,7 @@ DataAccessObject.create = function (data, callback) {
|
|||
if (err) {
|
||||
return callback(err, obj);
|
||||
}
|
||||
obj.__persisted = true;
|
||||
saveDone.call(obj, function () {
|
||||
createDone.call(obj, function () {
|
||||
callback(err, obj);
|
||||
|
@ -961,8 +962,7 @@ DataAccessObject.prototype.save = function (options, callback) {
|
|||
if (err) {
|
||||
return callback(err, inst);
|
||||
}
|
||||
inst._initProperties(data);
|
||||
inst.__persisted = true;
|
||||
inst._initProperties(data, { persisted: true });
|
||||
updateDone.call(inst, function () {
|
||||
saveDone.call(inst, function () {
|
||||
callback(err, inst);
|
||||
|
|
|
@ -69,7 +69,9 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
|
|||
strict = ctor.definition.settings.strict;
|
||||
}
|
||||
|
||||
if (options.persisted !== undefined) {
|
||||
this.__persisted = options.persisted === true;
|
||||
}
|
||||
|
||||
if (ctor.hideInternalProperties) {
|
||||
// Object.defineProperty() is expensive. We only try to make the internal
|
||||
|
|
|
@ -41,6 +41,18 @@ describe('manipulation', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should instantiate an object', function (done) {
|
||||
var p = new Person({name: 'Anatoliy'});
|
||||
p.name.should.equal('Anatoliy');
|
||||
p.isNewRecord().should.be.true;
|
||||
p.save(function(err, inst) {
|
||||
should.not.exist(err);
|
||||
inst.isNewRecord().should.be.false;
|
||||
inst.should.equal(p);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return instance of object', function (done) {
|
||||
var person = Person.create(function (err, p) {
|
||||
p.id.should.eql(person.id);
|
||||
|
@ -51,13 +63,28 @@ describe('manipulation', function () {
|
|||
should.not.exist(person.id);
|
||||
});
|
||||
|
||||
it('should not allow user-defined value for the id of object', function (done) {
|
||||
it('should not allow user-defined value for the id of object - create', function (done) {
|
||||
Person.create({id: 123456}, function (err, p) {
|
||||
err.should.be.instanceof(ValidationError);
|
||||
err.message.should.equal('The `Person` instance is not valid. Details: `id` can\'t be set.');
|
||||
err.statusCode.should.equal(422);
|
||||
p.should.be.instanceof(Person);
|
||||
p.id.should.equal(123456);
|
||||
p.isNewRecord().should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not allow user-defined value for the id of object - save', function (done) {
|
||||
var p = new Person({id: 123456});
|
||||
p.isNewRecord().should.be.true;
|
||||
p.save(function(err, inst) {
|
||||
err.should.be.instanceof(ValidationError);
|
||||
err.message.should.equal('The `Person` instance is not valid. Details: `id` can\'t be set.');
|
||||
err.statusCode.should.equal(422);
|
||||
inst.isNewRecord().should.be.true;
|
||||
inst.id.should.equal(123456);
|
||||
inst.isNewRecord().should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue