Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Fix ie 1223 status #359

Merged
merged 2 commits into from
Jun 2, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ function Browser(window, document, body, XHR, $log) {
});
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
completeOutstandingRequest(callback, xhr.status || 200, xhr.responseText);
// normalize IE bug (http://bugs.jquery.com/ticket/1450)
var status = xhr.status == 1223 ? 204 : xhr.status || 200;
completeOutstandingRequest(callback, status, xhr.responseText);
}
};
xhr.send(post || '');
Expand Down
27 changes: 20 additions & 7 deletions test/BrowserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ describe('browser', function(){
it('should process callbacks immedietly with no outstanding requests', function(){
var callback = jasmine.createSpy('callback');
browser.notifyWhenNoOutstandingRequests(callback);
expect(callback).wasCalled();
expect(callback).toHaveBeenCalled();
});

it('should queue callbacks with outstanding requests', function(){
var callback = jasmine.createSpy('callback');
browser.xhr('GET', '/url', null, noop);
browser.notifyWhenNoOutstandingRequests(callback);
expect(callback).not.wasCalled();
expect(callback).not.toHaveBeenCalled();

xhr.readyState = 4;
xhr.onreadystatechange();
expect(callback).wasCalled();
expect(callback).toHaveBeenCalled();
});
});

Expand All @@ -83,7 +83,7 @@ describe('browser', function(){
log += code + ':' + data + ';';
});
browser.notifyWhenNoOutstandingRequests(callback);
expect(callback).not.wasCalled();
expect(callback).not.toHaveBeenCalled();
expect(scripts.length).toEqual(1);
var script = scripts[0];
script.remove = function(){
Expand All @@ -93,7 +93,7 @@ describe('browser', function(){
expect(url[0]).toEqual('http://example.org/path');
expect(typeof fakeWindow[url[1]]).toEqual($function);
fakeWindow[url[1]]('data');
expect(callback).wasCalled();
expect(callback).toHaveBeenCalled();
expect(log).toEqual('remove();200:data;');
expect(typeof fakeWindow[url[1]]).toEqual('undefined');
});
Expand Down Expand Up @@ -124,6 +124,19 @@ describe('browser', function(){
expect(response).toEqual('RESPONSE');
});

it('should normalize IE\'s 1223 status code into 204', function() {
var callback = jasmine.createSpy('XHR');

browser.xhr('GET', 'URL', 'POST', callback);

xhr.status = 1223;
xhr.readyState = 4;
xhr.onreadystatechange();

expect(callback).toHaveBeenCalled();
expect(callback.argsForCall[0][0]).toEqual(204);
});

it('should not set Content-type header for GET requests', function() {
browser.xhr('GET', 'URL', 'POST-DATA', function(c, r) {});

Expand Down Expand Up @@ -159,10 +172,10 @@ describe('browser', function(){
it('should update outstandingRequests counter', function() {
var callback = jasmine.createSpy('callback');
browser.defer(callback);
expect(callback).not.wasCalled();
expect(callback).not.toHaveBeenCalled();

fakeSetTimeout.flush();
expect(callback).wasCalled();
expect(callback).toHaveBeenCalled();
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/JsonSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ describe('json', function(){
var spy = this.spyOn(JSON, 'parse').andCallThrough();

expect(fromJson('{}')).toEqual({});
expect(spy).wasNotCalled();
expect(spy).not.toHaveBeenCalled();

expect(fromJson('{}', true)).toEqual({});
expect(spy).wasCalled();
expect(spy).toHaveBeenCalled();
});


Expand Down
22 changes: 11 additions & 11 deletions test/ResourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ describe("resource", function() {

var cc = CreditCard.save({name:'misko'}, callback);
nakedExpect(cc).toEqual({name:'misko'});
expect(callback).wasNotCalled();
expect(callback).not.toHaveBeenCalled();
xhr.flush();
nakedExpect(cc).toEqual({id:123, name:'misko'});
expect(callback).wasCalledWith(cc);
expect(callback).toHaveBeenCalledWith(cc);
});

it("should read resource", function(){
xhr.expectGET("/CreditCard/123").respond({id:123, number:'9876'});
var cc = CreditCard.get({id:123}, callback);
expect(cc instanceof CreditCard).toBeTruthy();
nakedExpect(cc).toEqual({});
expect(callback).wasNotCalled();
expect(callback).not.toHaveBeenCalled();
xhr.flush();
nakedExpect(cc).toEqual({id:123, number:'9876'});
expect(callback).wasCalledWith(cc);
expect(callback).toHaveBeenCalledWith(cc);
});

it("should read partial resource", function(){
Expand All @@ -106,7 +106,7 @@ describe("resource", function() {
expect(cc.number).not.toBeDefined();
cc.$get(callback);
xhr.flush();
expect(callback).wasCalledWith(cc);
expect(callback).toHaveBeenCalledWith(cc);
expect(cc.number).toEqual('9876');
});

Expand All @@ -115,7 +115,7 @@ describe("resource", function() {

var cc = CreditCard.save({id:{key:123}, name:'misko'}, callback);
nakedExpect(cc).toEqual({id:{key:123}, name:'misko'});
expect(callback).wasNotCalled();
expect(callback).not.toHaveBeenCalled();
xhr.flush();
});

Expand All @@ -124,10 +124,10 @@ describe("resource", function() {

var ccs = CreditCard.query({key:'value'}, callback);
expect(ccs).toEqual([]);
expect(callback).wasNotCalled();
expect(callback).not.toHaveBeenCalled();
xhr.flush();
nakedExpect(ccs).toEqual([{id:1}, {id:2}]);
expect(callback).wasCalledWith(ccs);
expect(callback).toHaveBeenCalledWith(ccs);
});

it("should have all arguments optional", function(){
Expand All @@ -143,14 +143,14 @@ describe("resource", function() {
xhr.expectDELETE("/CreditCard/123").respond(200, {});

CreditCard.remove({id:123}, callback);
expect(callback).wasNotCalled();
expect(callback).not.toHaveBeenCalled();
xhr.flush();
nakedExpect(callback.mostRecentCall.args).toEqual([{}]);

callback.reset();
xhr.expectDELETE("/CreditCard/333").respond(204, null);
CreditCard.remove({id:333}, callback);
expect(callback).wasNotCalled();
expect(callback).not.toHaveBeenCalled();
xhr.flush();
nakedExpect(callback.mostRecentCall.args).toEqual([{}]);
});
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("resource", function() {
nakedExpect(cc).toEqual({name:'misko'});
xhr.flush();
nakedExpect(cc).toEqual({id:123});
expect(callback).wasCalledWith(cc);
expect(callback).toHaveBeenCalledWith(cc);
});

it('should not mutate the resource object if response contains no body', function(){
Expand Down
2 changes: 1 addition & 1 deletion test/ScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('scope/model', function(){
var onEval = jasmine.createSpy('onEval');
model.$onEval(onEval);
model.$eval('');
expect(onEval).wasNotCalled();
expect(onEval).not.toHaveBeenCalled();
});

it('should ignore none string/function', function(){
Expand Down
6 changes: 3 additions & 3 deletions test/ValidatorsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ describe('ValidatorTest', function(){

var spy = jasmine.createSpy();
asynchronous.call(self, "kai", spy);
expect(spy).wasNotCalled();
expect(spy).not.toHaveBeenCalled();

asynchronous.call(self, "misko", spy);
expect(spy).wasCalled();
expect(spy).toHaveBeenCalled();
});

it("should ignore old callbacks, and not remove spinner", function(){
Expand All @@ -156,7 +156,7 @@ describe('ValidatorTest', function(){
scope.updateFn = jasmine.createSpy();
scope.name = 'misko';
scope.$eval();
expect(scope.asyncFn).wasCalledWith('misko', scope.asyncFn.mostRecentCall.args[1]);
expect(scope.asyncFn).toHaveBeenCalledWith('misko', scope.asyncFn.mostRecentCall.args[1]);
assertTrue(scope.$element.hasClass('ng-input-indicator-wait'));
scope.asyncFn.mostRecentCall.args[1]('myError', {id: 1234, data:'data'});
assertFalse(scope.$element.hasClass('ng-input-indicator-wait'));
Expand Down
8 changes: 4 additions & 4 deletions test/service/deferSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ describe('$defer', function() {
var eval = this.spyOn(scope, '$eval').andCallThrough();

$defer(function() {});
expect(eval).wasNotCalled();
expect(eval).not.toHaveBeenCalled();

$browser.defer.flush();
expect(eval).wasCalled();
expect(eval).toHaveBeenCalled();

eval.reset(); //reset the spy;

Expand All @@ -61,10 +61,10 @@ describe('$defer', function() {
var eval = this.spyOn(scope, '$eval').andCallThrough();

$defer(function() {throw "Test Error";});
expect(eval).wasNotCalled();
expect(eval).not.toHaveBeenCalled();

$browser.defer.flush();
expect(eval).wasCalled();
expect(eval).toHaveBeenCalled();
});

it('should allow you to specify the delay time', function(){
Expand Down
4 changes: 2 additions & 2 deletions test/service/xhr.bulkSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ describe('$xhr.bulk', function() {
$xhrBulk.flush(function(){ log += 'DONE';});
$browserXhr.flush();

expect($xhrError).wasCalled();
expect($xhrError).toHaveBeenCalled();
var cb = $xhrError.mostRecentCall.args[0].callback;
expect(typeof cb).toEqual($function);
expect($xhrError).wasCalledWith(
expect($xhrError).toHaveBeenCalledWith(
{url:'/req1', method:'GET', data:null, callback:cb},
{status:404, response:'NotFound'});

Expand Down
8 changes: 4 additions & 4 deletions test/service/xhr.cacheSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ describe('$xhr.cache', function() {

$browserXhr.expectGET('/url').respond('+');
cache('GET', '/url', null, callback);
expect(eval).wasNotCalled();
expect(eval).not.toHaveBeenCalled();

$browserXhr.flush();
expect(eval).wasCalled();
expect(eval).toHaveBeenCalled();

eval.reset(); //reset the spy

cache('GET', '/url', null, callback);
expect(eval).wasNotCalled();
expect(eval).not.toHaveBeenCalled();

$browser.defer.flush();
expect(eval).wasCalled();
expect(eval).toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion test/service/xhr.errorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('$xhr.error', function() {
$browserXhr.flush();
var cb = $xhrError.mostRecentCall.args[0].callback;
expect(typeof cb).toEqual($function);
expect($xhrError).wasCalledWith(
expect($xhrError).toHaveBeenCalledWith(
{url:'/req', method:'POST', data:'MyData', callback:cb},
{status:500, body:'MyError'});
});
Expand Down
2 changes: 1 addition & 1 deletion test/service/xhrSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('$xhr', function() {
$xhr('GET', '/reqGET', null, function(){ throw "MyException"; });
$browserXhr.flush();

expect($log.error).wasCalledWith("MyException");
expect($log.error).toHaveBeenCalledWith("MyException");
});


Expand Down