commit 37f566931923fda93994abba403e290974d05daa
parent 2525f8e532baed07f0809c7a4491d9a1dda93875
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 7 May 2015 01:00:45 -0400
Fix making an item a child item if it's in any collections
Diffstat:
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -1409,7 +1409,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
let changedCollections = yield Zotero.DB.columnQueryAsync(sql, this.id);
if (changedCollections.length) {
let parentItem = yield this.ObjectsClass.getByLibraryAndKeyAsync(
- this.libraryID, oldParentKey
+ this.libraryID, parentItemKey
)
for (let i=0; i<changedCollections.length; i++) {
yield parentItem.loadCollections();
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -204,6 +204,42 @@ describe("Zotero.Item", function () {
item.parentKey = false;
assert.isFalse(item.hasChanged());
});
+
+ it("should move a top-level note under another item", function* () {
+ var noteItem = new Zotero.Item('note');
+ var id = yield noteItem.save()
+ noteItem = yield Zotero.Items.getAsync(id);
+
+ var item = new Zotero.Item('book');
+ id = yield item.save();
+ var { libraryID, key } = Zotero.Items.getLibraryAndKeyFromID(id);
+
+ noteItem.parentKey = key;
+ yield noteItem.save();
+
+ assert.isFalse(noteItem.isTopLevelItem());
+ })
+
+ it("should remove top-level item from collections when moving it under another item", function* () {
+ // Create a collection
+ var collection = new Zotero.Collection;
+ collection.name = "Test";
+ var collectionID = yield collection.save();
+
+ // Create a top-level note and add it to a collection
+ var noteItem = new Zotero.Item('note');
+ noteItem.addToCollection(collectionID);
+ var id = yield noteItem.save()
+ noteItem = yield Zotero.Items.getAsync(id);
+
+ var item = new Zotero.Item('book');
+ id = yield item.save();
+ var { libraryID, key } = Zotero.Items.getLibraryAndKeyFromID(id);
+ noteItem.parentKey = key;
+ yield noteItem.save();
+
+ assert.isFalse(noteItem.isTopLevelItem());
+ })
});
describe("#attachmentCharset", function () {