Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than first-class objects, stored in separate collectionRelations and itemRelations tables with ids for subjects, with foreign keys to the associated data objects. Related items now use dc:relation relations rather than a separate table (among other reasons, because API syncing won't necessarily sync both items at the same time, so they can't be stored by id). The UI assigns related-item relations bidirectionally, and checks for related-item and linked-object relations are done unidirectionally by default. dc:isReplacedBy is now dc:replaces, so that the subject is an existing object, and the predicate is now named Zotero.Attachments.replacedItemPredicate. Some additional work is still needed, notably around following replaced-item relations, and migration needs to be tested more fully, but this seems to mostly work.
This commit is contained in:
parent
75bcfcb685
commit
a740658452
24 changed files with 1414 additions and 812 deletions
|
@ -13,6 +13,78 @@ describe("Zotero.Items", function () {
|
|||
win.close();
|
||||
})
|
||||
|
||||
|
||||
describe("#merge()", function () {
|
||||
it("should merge two items", function* () {
|
||||
var item1 = yield createDataObject('item');
|
||||
var item2 = yield createDataObject('item');
|
||||
var item2URI = Zotero.URI.getItemURI(item2);
|
||||
|
||||
yield Zotero.Items.merge(item1, [item2]);
|
||||
|
||||
assert.isFalse(item1.deleted);
|
||||
assert.isTrue(item2.deleted);
|
||||
|
||||
// Check for merge-tracking relation
|
||||
var rels = item1.getRelationsByPredicate(Zotero.Relations.replacedItemPredicate);
|
||||
assert.lengthOf(rels, 1);
|
||||
assert.equal(rels[0], item2URI);
|
||||
})
|
||||
|
||||
it("should move merge-tracking relation from replaced item to master", function* () {
|
||||
var item1 = yield createDataObject('item');
|
||||
var item2 = yield createDataObject('item');
|
||||
var item2URI = Zotero.URI.getItemURI(item2);
|
||||
var item3 = yield createDataObject('item');
|
||||
var item3URI = Zotero.URI.getItemURI(item3);
|
||||
|
||||
yield Zotero.Items.merge(item2, [item3]);
|
||||
yield Zotero.Items.merge(item1, [item2]);
|
||||
|
||||
// Check for merge-tracking relation from 1 to 3
|
||||
var rels = item1.getRelationsByPredicate(Zotero.Relations.replacedItemPredicate);
|
||||
assert.lengthOf(rels, 2);
|
||||
assert.sameMembers(rels, [item2URI, item3URI]);
|
||||
})
|
||||
|
||||
it("should update relations pointing to replaced item to point to master", function* () {
|
||||
var item1 = yield createDataObject('item');
|
||||
var item1URI = Zotero.URI.getItemURI(item1);
|
||||
var item2 = yield createDataObject('item');
|
||||
var item2URI = Zotero.URI.getItemURI(item2);
|
||||
var item3 = createUnsavedDataObject('item');
|
||||
var predicate = Zotero.Relations.relatedItemPredicate;
|
||||
item3.addRelation(predicate, item2URI);
|
||||
yield item3.saveTx();
|
||||
|
||||
yield Zotero.Items.merge(item1, [item2]);
|
||||
|
||||
// Check for related-item relation from 3 to 1
|
||||
var rels = item3.getRelationsByPredicate(predicate);
|
||||
assert.deepEqual(rels, [item1URI]);
|
||||
})
|
||||
|
||||
it("should not update relations pointing to replaced item in other libraries", function* () {
|
||||
var group1 = yield createGroup();
|
||||
var group2 = yield createGroup();
|
||||
|
||||
var item1 = yield createDataObject('item', { libraryID: group1.libraryID });
|
||||
var item1URI = Zotero.URI.getItemURI(item1);
|
||||
var item2 = yield createDataObject('item', { libraryID: group1.libraryID });
|
||||
var item2URI = Zotero.URI.getItemURI(item2);
|
||||
var item3 = createUnsavedDataObject('item', { libraryID: group2.libraryID });
|
||||
var predicate = Zotero.Relations.linkedObjectPredicate;
|
||||
item3.addRelation(predicate, item2URI);
|
||||
yield item3.saveTx();
|
||||
|
||||
yield Zotero.Items.merge(item1, [item2]);
|
||||
|
||||
// Check for related-item relation from 3 to 2
|
||||
var rels = item3.getRelationsByPredicate(predicate);
|
||||
assert.deepEqual(rels, [item2URI]);
|
||||
})
|
||||
})
|
||||
|
||||
describe("#emptyTrash()", function () {
|
||||
it("should delete items in the trash", function* () {
|
||||
var item1 = createUnsavedDataObject('item');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue