Skip to content

Commit

Permalink
Merge pull request #85 from LevelbossMike/master
Browse files Browse the repository at this point in the history
Only start uploader when all files have been setup
  • Loading branch information
tim-evans authored Nov 23, 2016
2 parents fd9129f + c9bd9ac commit 6581fb6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 3 additions & 1 deletion addon/system/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export default Ember.Object.extend({
if (this.file.status === plupload.FAILED) {
this.file.status = plupload.QUEUED;
}
uploader.start();
if (this.get('queue').every((f) => f.settings)) {
uploader.start();
}
}

return this._deferred.promise;
Expand Down
3 changes: 2 additions & 1 deletion addon/system/upload-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export default Ember.ArrayProxy.extend({
for (let i = 0, len = files.length; i < len; i++) {
var file = File.create({
uploader: uploader,
file: files[i]
file: files[i],
queue: this
});

this.pushObject(file);
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/system/file-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Ember from 'ember';
import UploadQueue from 'ember-plupload/system/upload-queue';
import File from 'ember-plupload/system/file';
import {
module,
test
} from 'qunit';

module('File', {
});

test("#upload - it will only call its uploader's start method when all queued files have been setup (settings are set on all files)", function(assert) {
assert.expect(3);
let uploadCalls = 0;
const TestableFile = File.extend({
upload() {
uploadCalls++;
return this._super(...arguments);
}
});

const uploader = Ember.Object.extend({
start() {
assert.equal(uploadCalls, 2, 'Uploader was only started after both files were setup');
}
}).create();

const fileToUpload1 = {id: 1};
const fileToUpload2 = {id: 2};
const queue = UploadQueue.create();
const file1 = TestableFile.create({uploader, queue, file: fileToUpload1});
const file2 = TestableFile.create({uploader, queue, file: fileToUpload2});

queue.pushObject(file1);
queue.pushObject(file2);

file2.upload('www.example.com');
assert.equal(uploadCalls, 1, 'first file called #upload');
file1.upload('www.example.com');
assert.equal(uploadCalls, 2, 'second file called #upload');
});

0 comments on commit 6581fb6

Please sign in to comment.