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.
2015-06-02 00:09:39 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("Zotero.Relations", function () {
|
|
|
|
describe("#getByPredicateAndObject()", function () {
|
|
|
|
it("should return items matching predicate and object", function* () {
|
|
|
|
var item = createUnsavedDataObject('item');
|
|
|
|
item.setRelations({
|
|
|
|
"dc:relation": [
|
|
|
|
"http://zotero.org/users/1/items/SHREREMS"
|
|
|
|
],
|
|
|
|
"owl:sameAs": [
|
|
|
|
"http://zotero.org/groups/1/items/SRRMGSRM",
|
|
|
|
"http://zotero.org/groups/1/items/GSMRRSSM"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
yield item.saveTx();
|
2016-03-18 08:04:33 +00:00
|
|
|
var objects = Zotero.Relations.getByPredicateAndObject(
|
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.
2015-06-02 00:09:39 +00:00
|
|
|
'item', 'owl:sameAs', 'http://zotero.org/groups/1/items/SRRMGSRM'
|
|
|
|
);
|
|
|
|
assert.lengthOf(objects, 1);
|
|
|
|
assert.equal(objects[0], item);
|
|
|
|
})
|
|
|
|
})
|
2015-06-04 23:25:45 +00:00
|
|
|
|
|
|
|
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* () {
|
2017-03-02 04:34:11 +00:00
|
|
|
yield Zotero.Relations.updateUser(null, 1);
|
2015-06-04 23:25:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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* () {
|
2017-03-02 04:34:11 +00:00
|
|
|
yield Zotero.Relations.updateUser(1, 2);
|
2015-06-04 23:25:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
|
|
|
assert.include(rels[0], "/users/2");
|
|
|
|
})
|
|
|
|
})
|
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.
2015-06-02 00:09:39 +00:00
|
|
|
})
|