Add .library to Zotero.DataObject

This should replace uses of Zotero.Libraries.get(item.libraryID).
This commit is contained in:
Dan Stillman 2016-04-10 19:46:10 -04:00
parent 0469d6506a
commit a1ef16a0a6
2 changed files with 20 additions and 0 deletions

View file

@ -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
});

View file

@ -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) {