Fix some property access issues

- Return `undefined` instead of throwing an error trying to access
  `libraryTypeID` on a Zotero.Feed -- this fixes a test failure with
  the latest Chai, which annoyingly runs inspect() on an object passed
  to .include() regardless of whether the test succeeds
- Make some deprecated properties non-enumerable to avoid unnecessary
  logging when the object is dumped
This commit is contained in:
Dan Stillman 2017-10-27 03:21:00 -04:00
parent 241df13954
commit e22d7a8459
5 changed files with 20 additions and 4 deletions
chrome/content/zotero/xpcom/data
test/tests

View File

@ -80,7 +80,8 @@ Zotero.defineProperty(Zotero.Collection.prototype, 'parent', {
set: function(val) { set: function(val) {
Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2); Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2);
this.parentID = val; this.parentID = val;
} },
enumerable: false
}); });
Zotero.defineProperty(Zotero.Collection.prototype, 'treeViewID', { Zotero.defineProperty(Zotero.Collection.prototype, 'treeViewID', {

View File

@ -114,6 +114,11 @@ Zotero.defineProperty(Zotero.Feed.prototype, 'isFeed', {
Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypes', { Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypes', {
value: Object.freeze(Zotero.Feed._super.prototype.libraryTypes.concat(['feed'])) value: Object.freeze(Zotero.Feed._super.prototype.libraryTypes.concat(['feed']))
}); });
Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypeID', {
get: () => undefined
});
Zotero.defineProperty(Zotero.Feed.prototype, 'unreadCount', { Zotero.defineProperty(Zotero.Feed.prototype, 'unreadCount', {
get: function() { return this._feedUnreadCount; } get: function() { return this._feedUnreadCount; }
}); });

View File

@ -105,7 +105,8 @@ Zotero.defineProperty(Zotero.Item.prototype, 'itemID', {
get: function() { get: function() {
Zotero.debug("Item.itemID is deprecated -- use Item.id"); Zotero.debug("Item.itemID is deprecated -- use Item.id");
return this._id; return this._id;
} },
enumerable: false
}); });
Zotero.defineProperty(Zotero.Item.prototype, 'libraryID', { Zotero.defineProperty(Zotero.Item.prototype, 'libraryID', {
get: function() { return this._libraryID; }, get: function() { return this._libraryID; },
@ -2685,7 +2686,8 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentMIMEType', {
get: function() { get: function() {
Zotero.debug(".attachmentMIMEType deprecated -- use .attachmentContentType"); Zotero.debug(".attachmentMIMEType deprecated -- use .attachmentContentType");
return this.attachmentContentType; return this.attachmentContentType;
} },
enumerable: false
}); });
/** /**

View File

@ -142,7 +142,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'libraryTypeID', {
return Zotero.Groups.getGroupIDFromLibraryID(this._libraryID); return Zotero.Groups.getGroupIDFromLibraryID(this._libraryID);
default: default:
throw new Error(`Cannot return library type id for ${this._libraryType} library`); throw new Error(`Tried to get library type id for ${this._libraryType} library`);
} }
} }
}); });
@ -169,6 +169,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'name', {
return Zotero.getString('pane.collections.library'); return Zotero.getString('pane.collections.library');
} }
// This property is provided by the extending objects (Group, Feed) for other library types
throw new Error('Unhandled library type "' + this._libraryType + '"'); throw new Error('Unhandled library type "' + this._libraryType + '"');
} }
}); });

View File

@ -50,6 +50,13 @@ describe("Zotero.Feed", function() {
}); });
}); });
describe("#libraryTypeID", function () {
it("should be undefind", function* () {
let feed = yield createFeed();
assert.isUndefined(feed.libraryTypeID);
});
});
describe("#url", function() { describe("#url", function() {
it("should throw if trying to set an invalid URL", function *() { it("should throw if trying to set an invalid URL", function *() {
let feed = new Zotero.Feed({ name: 'Test ' + Zotero.randomString() }); let feed = new Zotero.Feed({ name: 'Test ' + Zotero.randomString() });