Add .library to Zotero.DataObject
This should replace uses of Zotero.Libraries.get(item.libraryID).
This commit is contained in:
parent
0469d6506a
commit
a1ef16a0a6
2 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue