commit a2b572665d969d69ecb8824fef019f8ad2d1ede8
parent 30535653a6f61b937805f2fe5da174c56d49d038
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 26 Apr 2015 02:09:44 -0400
Make libraryID optional for DataObjects, defaulting to user library
Diffstat:
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js
@@ -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;
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -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();
diff --git a/test/tests/itemsTest.js b/test/tests/itemsTest.js
@@ -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';
});