commit 258b70b455c3c23743ef1f1014a7d401a1792d57
parent cd4d084dd961b742842c69e57f6c0acff797e062
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 20 Jul 2015 04:14:51 -0400
Throw an error saving an empty item with no item type
Diffstat:
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -1082,6 +1082,13 @@ Zotero.Item.prototype.isEditable = function() {
return true;
}
+Zotero.Item.prototype._initSave = Zotero.Promise.coroutine(function* (env) {
+ if (!this.itemTypeID) {
+ throw new Error("Item type must be set before saving");
+ }
+ return Zotero.Item._super.prototype._initSave.apply(this, arguments);
+})
+
Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
Zotero.DB.requireTransaction();
@@ -1090,9 +1097,6 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
var libraryType = env.libraryType = Zotero.Libraries.getType(env.libraryID);
var itemTypeID = this.itemTypeID;
- if (!itemTypeID) {
- throw new Error("Item type must be set before saving");
- }
var reloadParentChildItems = {};
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -682,6 +682,15 @@ describe("Zotero.Item", function () {
})
})
+ describe("#save()", function () {
+ it("should throw an error for an empty item without an item type", function* () {
+ var item = new Zotero.Item;
+ var e = yield getPromiseError(item.saveTx());
+ assert.ok(e);
+ assert.equal(e.message, "Item type must be set before saving");
+ })
+ })
+
describe("#clone()", function () {
// TODO: Expand to other data
it("should copy creators", function* () {