Throw an error saving an empty item with no item type
This commit is contained in:
parent
cd4d084dd9
commit
258b70b455
2 changed files with 16 additions and 3 deletions
|
@ -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 = {};
|
||||
|
||||
|
|
|
@ -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* () {
|
||||
|
|
Loading…
Add table
Reference in a new issue