www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit e9fd7f2dd159409f39cc8fb6765c83f9dfb3cb5e
parent dd5ae0f49c3760db88061844c8a5bdea509c50f1
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue,  7 Mar 2017 01:54:49 -0500

Update Collection::getChildItems() when erasing item

Fixes #1188

Diffstat:
Mchrome/content/zotero/xpcom/data/item.js | 2+-
Mtest/tests/collectionTest.js | 28++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -3944,7 +3944,7 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) { Zotero.DB.requireTransaction(); // Remove item from parent collections - var parentCollectionIDs = this.collections; + var parentCollectionIDs = this._collections; if (parentCollectionIDs) { for (var i=0; i<parentCollectionIDs.length; i++) { let parentCollection = yield Zotero.Collections.getAsync(parentCollectionIDs[i]); diff --git a/test/tests/collectionTest.js b/test/tests/collectionTest.js @@ -227,6 +227,25 @@ describe("Zotero.Collection", function() { assert.lengthOf(collection.getChildItems(false, true), 1); }) + + it("should not include removed items", function* () { + var col = yield createDataObject('collection'); + var item = yield createDataObject('item', { collections: [ col.id ] }); + assert.lengthOf(col.getChildItems(), 1); + item.setCollections([]); + yield item.saveTx(); + Zotero.debug(col.getChildItems()); + assert.lengthOf(col.getChildItems(), 0); + }); + + it("should not include deleted items", function* () { + var col = yield createDataObject('collection'); + var item = yield createDataObject('item', { collections: [ col.id ] }); + assert.lengthOf(col.getChildItems(), 1); + yield item.erase(); + Zotero.debug(col.getChildItems()); + assert.lengthOf(col.getChildItems(), 0); + }); }) describe("#toJSON()", function () { @@ -293,5 +312,14 @@ describe("Zotero.Collection", function() { ] ); }); + + it("should not include deleted items", function* () { + var col = yield createDataObject('collection'); + var item = yield createDataObject('item', { collections: [col.id] }); + assert.lengthOf(col.getDescendents(), 1); + yield item.eraseTx(); + assert.lengthOf(col.getDescendents(), 0); + }); + }); })