diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index 19ce3f9c8b..0615098335 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -74,6 +74,11 @@ Zotero.defineProperty(Zotero.DataObject.prototype, 'id', { Zotero.defineProperty(Zotero.DataObject.prototype, 'libraryID', { get: function() this._libraryID }); +Zotero.defineProperty(Zotero.DataObject.prototype, 'library', { + get: function () { + return Zotero.Libraries.get(this._libraryID); + } +}); Zotero.defineProperty(Zotero.DataObject.prototype, 'key', { get: function() this._key }); diff --git a/test/tests/dataObjectTest.js b/test/tests/dataObjectTest.js index 29251a6d21..977138d140 100644 --- a/test/tests/dataObjectTest.js +++ b/test/tests/dataObjectTest.js @@ -3,6 +3,21 @@ describe("Zotero.DataObject", function() { var types = ['collection', 'item', 'search']; + describe("#library", function () { + it("should return a Zotero.Library", function* () { + var item = yield createDataObject('item'); + assert.equal(item.library, Zotero.Libraries.userLibrary); + }); + }); + + describe("#libraryID", function () { + it("should return a libraryID", function* () { + var item = yield createDataObject('item'); + assert.isNumber(item.libraryID); + assert.equal(item.libraryID, Zotero.Libraries.userLibraryID); + }); + }); + describe("#key", function () { it("shouldn't update .loaded on get if unset", function* () { for (let type of types) {