Update Zotero.Relations.updateUser() for new relations schema
Also adds Zotero.DataObjects::getLoaded(), which returns an array of all loaded objects of the given type. This is useful for selective reloading, for example with item.reload(['relations'], true).
This commit is contained in:
parent
195a737049
commit
aa2e0a8582
3 changed files with 70 additions and 23 deletions
|
@ -21,4 +21,47 @@ describe("Zotero.Relations", function () {
|
|||
assert.equal(objects[0], item);
|
||||
})
|
||||
})
|
||||
|
||||
describe("#updateUser", function () {
|
||||
beforeEach(function* () {
|
||||
yield Zotero.DB.queryAsync("DELETE FROM settings WHERE setting='account'");
|
||||
yield Zotero.Users.init();
|
||||
})
|
||||
|
||||
it("should update relations using local user key to use userID", function* () {
|
||||
var item1 = yield createDataObject('item');
|
||||
var item2 = createUnsavedDataObject('item');
|
||||
item2.addRelatedItem(item1);
|
||||
yield item2.save();
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
assert.include(rels[0], "/users/local");
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Relations.updateUser(1);
|
||||
})
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
assert.include(rels[0], "/users/1");
|
||||
})
|
||||
|
||||
it("should update relations from one userID to another", function* () {
|
||||
yield Zotero.Users.setCurrentUserID(1);
|
||||
|
||||
var item1 = yield createDataObject('item');
|
||||
var item2 = createUnsavedDataObject('item');
|
||||
item2.addRelatedItem(item1);
|
||||
yield item2.save();
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
assert.include(rels[0], "/users/1");
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Relations.updateUser(2);
|
||||
});
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
assert.include(rels[0], "/users/2");
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue