Skip to content

Commit

Permalink
Pass the XMLHttpRequest to the send method
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jan 17, 2012
1 parent b593986 commit 9ab2a20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 3 additions & 4 deletions public/javascripts/jquery.attach.js
Expand Up @@ -176,7 +176,7 @@ var Attach = {};
*/
Attach.readSuccess = function(event) {
var uploader = new Attach.Uploader(event.target);
uploader.send();
uploader.send(new XMLHttpRequest());
};

/*
Expand Down Expand Up @@ -224,10 +224,9 @@ var Attach = {};
/*
* Send the file to the server via xhr.
*
* uploader.send();
* uploader.send(new XmlHttpRequest());
*/
Attach.Uploader.prototype.send = function() {
var request = new XMLHttpRequest();
Attach.Uploader.prototype.send = function(request) {
this.attachEvents(request);
this.prepareRequest(request);
request.send(this.file());
Expand Down
23 changes: 23 additions & 0 deletions spec/javascripts/jquery.attach_spec.js
Expand Up @@ -128,5 +128,28 @@ describe("jquery Attach", function() {
expect(uploader.file()).toEqual(file);
});
});

describe("#send", function() {

var request;
var reader;

beforeEach(function() {
reader = new Attach.Reader(file, url);
Attach.readers.push(reader);
request = new XMLHttpRequest();
spyOn(request, "send");
});

it("reads the file", function() {
uploader.send(request);
expect(request.send).toHaveBeenCalledWith(file);
});

it("pops the reader off the stack", function() {
uploader.send(request);
expect(Attach.readers.length).toEqual(0);
});
});
});
});

0 comments on commit 9ab2a20

Please sign in to comment.