diff options
| author | Karl Seamon | 2011-08-18 15:07:04 -0400 |
|---|---|---|
| committer | Igor Minar | 2011-08-19 01:17:20 -0700 |
| commit | c37bfde9eb31556ee1eb146795b0c1f1504a4a26 (patch) | |
| tree | 82291d3c1c784081e5056bd5b5f771e9bc8f9c03 | |
| parent | f6bcbb53f056372d6778fedfc793435fc2e88e11 (diff) | |
| download | angular.js-c37bfde9eb31556ee1eb146795b0c1f1504a4a26.tar.bz2 | |
fix($resource): properly call error callback when resource is called with two arguments
| -rw-r--r-- | src/Resource.js | 7 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 21 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/Resource.js b/src/Resource.js index 3c149d8b..74d952ed 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -76,9 +76,16 @@ ResourceFactory.prototype = { case 4: error = a4; success = a3; + //fallthrough case 3: case 2: if (isFunction(a2)) { + if (isFunction(a1)) { + success = a1; + error = a2; + break; + } + success = a2; error = a3; //fallthrough diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 81519f0f..7bba9357 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -244,22 +244,35 @@ describe("resource", function() { describe('failure mode', function() { var ERROR_CODE = 500, - ERROR_RESPONSE = 'Server Error'; + ERROR_RESPONSE = 'Server Error', + errorCB; beforeEach(function() { - xhr.expectGET('/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE); + errorCB = jasmine.createSpy(); }); it('should report error when non 2xx if error callback is not provided', function() { + xhr.expectGET('/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE); CreditCard.get({id:123}); xhr.flush(); expect($xhrErr).toHaveBeenCalled(); }); it('should call the error callback if provided on non 2xx response', function() { - CreditCard.get({id:123}, noop, callback); + xhr.expectGET('/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE); + CreditCard.get({id:123}, callback, errorCB); + xhr.flush(); + expect(errorCB).toHaveBeenCalledWith(500, ERROR_RESPONSE); + expect(callback).not.toHaveBeenCalled(); + expect($xhrErr).not.toHaveBeenCalled(); + }); + + it('should call the error callback if provided on non 2xx response', function() { + xhr.expectGET('/CreditCard').respond(ERROR_CODE, ERROR_RESPONSE); + CreditCard.get(callback, errorCB); xhr.flush(); - expect(callback).toHaveBeenCalledWith(500, ERROR_RESPONSE); + expect(errorCB).toHaveBeenCalledWith(500, ERROR_RESPONSE); + expect(callback).not.toHaveBeenCalled(); expect($xhrErr).not.toHaveBeenCalled(); }); }); |
