Make libraryID optional for DataObjects, defaulting to user library
This commit is contained in:
parent
30535653a6
commit
a2b572665d
3 changed files with 3 additions and 9 deletions
|
@ -561,8 +561,9 @@ Zotero.DataObject.prototype.hasChanged = function() {
|
|||
}
|
||||
|
||||
Zotero.DataObject.prototype._initSave = Zotero.Promise.coroutine(function* (env) {
|
||||
if (!this.libraryID) {
|
||||
throw new Error("libraryID must be set before saving " + this._objectType);
|
||||
// Default to user library if not specified
|
||||
if (this.libraryID === null) {
|
||||
this.libraryID = Zotero.Libraries.userLibraryID;
|
||||
}
|
||||
|
||||
env.isNew = !this.id;
|
||||
|
|
|
@ -2,20 +2,17 @@ describe("Zotero.Item", function() {
|
|||
describe("#getField()", function () {
|
||||
it("should return false for valid unset fields on unsaved items", function* () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
assert.equal(item.getField('rights'), false);
|
||||
});
|
||||
|
||||
it("should return false for valid unset fields on unsaved items after setting on another field", function* () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
item.setField('title', 'foo');
|
||||
assert.equal(item.getField('rights'), false);
|
||||
});
|
||||
|
||||
it("should return false for invalid unset fields on unsaved items after setting on another field", function* () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
item.setField('title', 'foo');
|
||||
assert.equal(item.getField('invalid'), false);
|
||||
});
|
||||
|
@ -25,11 +22,9 @@ describe("Zotero.Item", function() {
|
|||
it("should create a child note", function () {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
var parentItemID = yield item.save();
|
||||
|
||||
item = new Zotero.Item('note');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
item.parentID = parentItemID;
|
||||
var childItemID = yield item.save();
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ describe("Zotero.Items", function() {
|
|||
it("should return a libraryID and key within a transaction", function* () {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
var itemID = yield item.save();
|
||||
|
||||
var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID);
|
||||
|
@ -19,7 +18,6 @@ describe("Zotero.Items", function() {
|
|||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
||||
itemID = yield item.save();
|
||||
throw 'Aborting transaction -- ignore';
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue