Attachment fixes

Change all attachment functions to take parameter objects, including a
'collections' property to assign collections. (Previously, calling code
assigned collections separately, which required a nested transaction,
which is no longer possible.)

Fixes #723, Can't attach files by dragging
This commit is contained in:
Dan Stillman 2015-05-23 04:25:47 -04:00
parent 6e2d1f683a
commit 3fc09add3a
9 changed files with 226 additions and 139 deletions

View file

@ -27,7 +27,10 @@ describe("Zotero.Attachments", function() {
var parentItemID = yield item.saveTx();
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile(tmpFile, parentItemID);
var itemID = yield Zotero.Attachments.importFromFile({
file: tmpFile,
parentItemID: parentItemID
});
var item = yield Zotero.Items.getAsync(itemID);
var storedFile = item.getFile();
assert.equal((yield Zotero.File.getContentsAsync(storedFile)), contents);
@ -36,6 +39,43 @@ describe("Zotero.Attachments", function() {
yield Zotero.Items.erase(itemID);
});
it("should create a top-level attachment from a PNG file", function* () {
var file = getTestDataDirectory();
file.append('test.png');
var contents = yield Zotero.File.getBinaryContentsAsync(file);
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile({
file: file
});
var item = yield Zotero.Items.getAsync(itemID);
var storedFile = item.getFile();
assert.equal((yield Zotero.File.getBinaryContentsAsync(storedFile)), contents);
// Clean up
yield Zotero.Items.erase(itemID);
});
it("should create a top-level attachment from a PNG file in a collection", function* () {
var file = getTestDataDirectory();
file.append('test.png');
var contents = yield Zotero.File.getBinaryContentsAsync(file);
var collection = yield createDataObject('collection');
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile({
file: file,
collections: [collection.id]
});
var item = yield Zotero.Items.getAsync(itemID);
var storedFile = item.getFile();
assert.equal((yield Zotero.File.getBinaryContentsAsync(storedFile)), contents);
// Clean up
yield Zotero.Items.erase(itemID);
});
it("should create a child attachment from a PNG file", function* () {
var file = getTestDataDirectory();
file.append('test.png');
@ -46,7 +86,10 @@ describe("Zotero.Attachments", function() {
var parentItemID = yield item.saveTx();
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile(file, parentItemID);
var itemID = yield Zotero.Attachments.importFromFile({
file: file,
parentItemID: parentItemID
});
var item = yield Zotero.Items.getAsync(itemID);
var storedFile = item.getFile();
assert.equal((yield Zotero.File.getBinaryContentsAsync(storedFile)), contents);