diff options
| author | Misko Hevery | 2013-01-17 22:01:50 -0800 |
|---|---|---|
| committer | Misko Hevery | 2013-01-17 23:08:39 -0800 |
| commit | af89daf4641f57b92be6c1f3635f5a3237f20c71 (patch) | |
| tree | 8dd01114b497cdc468bdf378ba3c841ad9e5f005 /test | |
| parent | 224d7d6e9023395e9bf3f7217984c04fd550f4e7 (diff) | |
| download | angular.js-af89daf4641f57b92be6c1f3635f5a3237f20c71.tar.bz2 | |
feat(ngResource): support all $http.config actions
This allows the transformation of the $http request in both directions,
headers, caching, and timeout.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ngResource/resourceSpec.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index b9041426..9373d347 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -427,4 +427,26 @@ describe("resource", function() { expect(callback).not.toHaveBeenCalled(); }); }); + + + it('should transform request/response', function() { + var Person = $resource('/Person/:id', {}, { + save: { + method: 'POST', + params: {id: '@id'}, + transformRequest: function(data) { + return angular.toJson({ __id: data.id }); + }, + transformResponse: function(data) { + return { id: data.__id }; + } + } + }); + + $httpBackend.expect('POST', '/Person/123', { __id: 123 }).respond({ __id: 456 }); + var person = new Person({id:123}); + person.$save(); + $httpBackend.flush(); + expect(person.id).toEqual(456); + }); }); |
