From 754d2541c41080ba8d2a20cbe04ce16b1742296f Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 4 Apr 2011 16:04:37 -0700 Subject: correct $resource's success callback execution succcess callbacks should be executed for status codes in the range of <200,300). --- src/Resource.js | 2 +- test/ResourceSpec.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Resource.js b/src/Resource.js index e2cd5a0e..d9121794 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -96,7 +96,7 @@ ResourceFactory.prototype = { route.url(extend({}, action.params || {}, extractParams(data), params)), data, function(status, response, clear) { - if (status == 200) { + if (200 <= status && status < 300) { if (response) { if (action.isArray) { value.length = 0; diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index e055beab..fe6c3fdf 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -139,13 +139,20 @@ describe("resource", function() { expect(log).toEqual('cb;'); }); - it('should delete resource', function(){ - xhr.expectDELETE("/CreditCard/123").respond({}); + it('should delete resource and call callback', function(){ + xhr.expectDELETE("/CreditCard/123").respond(200, {}); CreditCard.remove({id:123}, callback); expect(callback).wasNotCalled(); xhr.flush(); nakedExpect(callback.mostRecentCall.args).toEqual([{}]); + + callback.reset(); + xhr.expectDELETE("/CreditCard/333").respond(204, null); + CreditCard.remove({id:333}, callback); + expect(callback).wasNotCalled(); + xhr.flush(); + nakedExpect(callback.mostRecentCall.args).toEqual([{}]); }); it('should post charge verb', function(){ -- cgit v1.2.3