Default to user library when assigning unsaved item to collection

And fix some issues setting the libraryID property on unsaved objects

Also return .deleted as false, not an empty string
This commit is contained in:
Dan Stillman 2015-05-30 19:07:12 -04:00
parent ed1c0a4637
commit 420985661b
4 changed files with 168 additions and 137 deletions

View file

@ -43,4 +43,70 @@ describe("Zotero.DataObjects", function () {
}
});
});
describe("#_setIdentifier", function () {
it("should not allow an id change", function* () {
var item = yield createDataObject('item');
try {
item.id = item.id + 1;
}
catch (e) {
assert.equal(e.message, "ID cannot be changed");
return;
}
assert.fail("ID change allowed");
})
it("should not allow a key change", function* () {
var item = yield createDataObject('item');
try {
item.key = Zotero.DataObjectUtilities.generateKey();
}
catch (e) {
assert.equal(e.message, "Key cannot be changed");
return;
}
assert.fail("Key change allowed");
})
it("should not allow key to be set if id is set", function* () {
var item = createUnsavedDataObject('item');
item.id = Zotero.Utilities.rand(100000, 1000000);
try {
item.libraryID = Zotero.Libraries.userLibraryID;
item.key = Zotero.DataObjectUtilities.generateKey();
}
catch (e) {
assert.equal(e.message, "Cannot set key if id is already set");
return;
}
assert.fail("ID change allowed");
})
it("should not allow id to be set if key is set", function* () {
var item = createUnsavedDataObject('item');
item.libraryID = Zotero.Libraries.userLibraryID;
item.key = Zotero.DataObjectUtilities.generateKey();
try {
item.id = Zotero.Utilities.rand(100000, 1000000);
}
catch (e) {
assert.equal(e.message, "Cannot set id if key is already set");
return;
}
assert.fail("Key change allowed");
})
it("should not allow key to be set if library isn't set", function* () {
var item = createUnsavedDataObject('item');
try {
item.key = Zotero.DataObjectUtilities.generateKey();
}
catch (e) {
assert.equal(e.message, "libraryID must be set before key");
return;
}
assert.fail("libraryID change allowed");
})
})
})