correct $resource's success callback execution

succcess callbacks should be executed for status codes in the range
of <200,300).
This commit is contained in:
Igor Minar 2011-04-04 16:04:37 -07:00
parent 9bd2c3967b
commit 754d2541c4
2 changed files with 10 additions and 3 deletions

View file

@ -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;

View file

@ -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(){