Fix test for updateAttribute

This commit is contained in:
Anatoliy Chakkaev 2011-11-27 13:08:40 +07:00
parent 76a2f9a22c
commit 27af51a0d9
2 changed files with 11 additions and 3 deletions

View File

@ -392,6 +392,14 @@ AbstractClass.prototype.propertyChanged = function (attr) {
};
AbstractClass.prototype.reload = function (cb) {
var obj = this.constructor.cache[this.id];
if (obj) {
Object.keys(obj).forEach(function (k) {
if (obj.propertyChanged(k)) {
obj[k] = obj[k + '_was'];
}
});
}
this.constructor.find(this.id, cb);
};

View File

@ -218,13 +218,13 @@ function testOrm(schema) {
post.updateAttribute('title', 'New title', function () {
test.equal(post.title, 'New title');
test.ok(!post.propertyChanged('title'));
test.equal(post.content, 'New content');
test.equal(post.content, 'New content', 'dirty state saved');
test.ok(post.propertyChanged('content'));
post.reload(function () {
test.equal(post.title, 'New title');
test.ok(!post.propertyChanged('title'));
test.equal(post.content, 'content');
test.ok(!post.propertyChanged('content'));
test.equal(post.content, 'content', 'real value turned back');
test.ok(!post.propertyChanged('content'), 'content unchanged');
test.done();
});
});