From a8ea8656d267ed641f67c108d0e8d456089f6ab5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 15 May 2016 03:34:06 -0400 Subject: [PATCH] Fix sync error after changing child item to top-level --- .../zotero/xpcom/data/dataObjectUtilities.js | 1 + test/tests/collectionTest.js | 13 +++++++++++++ test/tests/itemTest.js | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js index f2ab4728dd..dfa737e58e 100644 --- a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js +++ b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js @@ -138,6 +138,7 @@ Zotero.DataObjectUtilities = { break; case 'deleted': + case 'parentItem': target[i] = false; break; diff --git a/test/tests/collectionTest.js b/test/tests/collectionTest.js index 964588c053..5b9a971fbc 100644 --- a/test/tests/collectionTest.js +++ b/test/tests/collectionTest.js @@ -201,6 +201,19 @@ describe("Zotero.Collection", function() { }) }) + describe("#toJSON()", function () { + it("should set 'parentCollection' to false when cleared", function* () { + var col1 = yield createDataObject('collection'); + var col2 = yield createDataObject('collection', { parentID: col1.id }); + // Create initial JSON with parentCollection + var patchBase = col2.toJSON(); + // Clear parent collection and regenerate JSON + col2.parentID = false; + var json = col2.toJSON({ patchBase }); + assert.isFalse(json.parentCollection); + }); + }); + describe("#getDescendents()", function () { var collection0, collection1, collection2, collection3, item1, item2, item3; diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 1b015f1951..31365dd7cd 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1138,6 +1138,18 @@ describe("Zotero.Item", function () { assert.isUndefined(json.title); assert.strictEqual(json.deleted, 1); }) + + it("should set 'parentItem' to false when cleared", function* () { + var item = yield createDataObject('item'); + var note = new Zotero.Item('note'); + note.parentID = item.id; + // Create initial JSON with parentItem + var patchBase = note.toJSON(); + // Clear parent item and regenerate JSON + note.parentID = false; + var json = note.toJSON({ patchBase }); + assert.isFalse(json.parentItem); + }); }) })