commit 7075300a172a03d99bb7b7908330eb296a0526ac
parent f02a9aa95e7fef508d7b04beac6af23f1cb177ac
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 2 Aug 2015 05:26:02 -0400
Fix hasChanged() bug related to 'synced'
Diffstat:
2 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js
@@ -776,6 +776,7 @@ Zotero.DataObject.prototype.hasChanged = function() {
var changed = Object.keys(this._changed).filter(dataType => this._changed[dataType]);
if (changed.length == 1
&& changed[0] == 'primaryData'
+ && Object.keys(this._changed.primaryData).length == 1
&& this._changed.primaryData.synced
&& this._previousData.synced == this._synced) {
return false;
diff --git a/test/tests/dataObjectTest.js b/test/tests/dataObjectTest.js
@@ -121,25 +121,6 @@ describe("Zotero.DataObject", function() {
}
});
- it("shouldn't cause a save if unchanged and nothing else changed", function* () {
- for (let type of types) {
- var obj = createUnsavedDataObject(type);
- obj.synced = true;
- var id = yield obj.saveTx();
- assert.isTrue(obj.synced);
-
- obj.synced = true;
- assert.isFalse(obj.hasChanged(), type + " shouldn't be changed");
-
- var obj = createUnsavedDataObject(type);
- obj.synced = false;
- var id = yield obj.saveTx();
- assert.isFalse(obj.synced);
- obj.synced = false;
- assert.isFalse(obj.hasChanged(), type + " shouldn't be changed");
- }
- })
-
it("should be unchanged if skipSyncedUpdate passed", function* () {
for (let type of types) {
var obj = createUnsavedDataObject(type);
@@ -212,6 +193,42 @@ describe("Zotero.DataObject", function() {
})
})
+
+ describe("#hasChanged()", function () {
+ it("should return false if 'synced' was set but unchanged and nothing else changed", function* () {
+ for (let type of types) {
+ // True
+ var obj = createUnsavedDataObject(type);
+ obj.synced = true;
+ var id = yield obj.saveTx();
+ assert.isTrue(obj.synced);
+
+ obj.synced = true;
+ assert.isFalse(obj.hasChanged(), type + " shouldn't be changed");
+
+ // False
+ var obj = createUnsavedDataObject(type);
+ obj.synced = false;
+ var id = yield obj.saveTx();
+ assert.isFalse(obj.synced);
+ obj.synced = false;
+ assert.isFalse(obj.hasChanged(), type + " shouldn't be changed");
+ }
+ })
+
+ it("should return true if 'synced' was set but unchanged and another primary field changed", function* () {
+ for (let type of types) {
+ let obj = createUnsavedDataObject(type);
+ obj.synced = true;
+ yield obj.saveTx();
+
+ obj.synced = true;
+ obj.version = 1234;
+ assert.isTrue(obj.hasChanged());
+ }
+ })
+ })
+
describe("#save()", function () {
it("should add new identifiers to cache", function* () {
// Collection