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

Commit 754d254

Browse files
committed
correct $resource's success callback execution
succcess callbacks should be executed for status codes in the range of <200,300).
1 parent 9bd2c39 commit 754d254

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ ResourceFactory.prototype = {
9696
route.url(extend({}, action.params || {}, extractParams(data), params)),
9797
data,
9898
function(status, response, clear) {
99-
if (status == 200) {
99+
if (200 <= status && status < 300) {
100100
if (response) {
101101
if (action.isArray) {
102102
value.length = 0;

test/ResourceSpec.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,20 @@ describe("resource", function() {
139139
expect(log).toEqual('cb;');
140140
});
141141

142-
it('should delete resource', function(){
143-
xhr.expectDELETE("/CreditCard/123").respond({});
142+
it('should delete resource and call callback', function(){
143+
xhr.expectDELETE("/CreditCard/123").respond(200, {});
144144

145145
CreditCard.remove({id:123}, callback);
146146
expect(callback).wasNotCalled();
147147
xhr.flush();
148148
nakedExpect(callback.mostRecentCall.args).toEqual([{}]);
149+
150+
callback.reset();
151+
xhr.expectDELETE("/CreditCard/333").respond(204, null);
152+
CreditCard.remove({id:333}, callback);
153+
expect(callback).wasNotCalled();
154+
xhr.flush();
155+
nakedExpect(callback.mostRecentCall.args).toEqual([{}]);
149156
});
150157

151158
it('should post charge verb', function(){

0 commit comments

Comments
 (0)