commit a1ef16a0a668d2f486d00c6ab5c32f433b5ae59f
parent 0469d6506a644ce2ac54ba4a077f6c25ab8d76d6
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 10 Apr 2016 19:46:10 -0400
Add .library to Zotero.DataObject
This should replace uses of Zotero.Libraries.get(item.libraryID).
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git 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
@@ -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) {