From 27af51a0d9bf16bf419cac424c32e95d232c2519 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Sun, 27 Nov 2011 13:08:40 +0700 Subject: [PATCH] Fix test for updateAttribute --- lib/abstract-class.js | 8 ++++++++ test/common_test.js | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 4d079648..2fa12c7b 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -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); }; diff --git a/test/common_test.js b/test/common_test.js index 25526927..9d6dd710 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -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(); }); });