From af89daf4641f57b92be6c1f3635f5a3237f20c71 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 17 Jan 2013 22:01:50 -0800 Subject: feat(ngResource): support all $http.config actions This allows the transformation of the $http request in both directions, headers, caching, and timeout. --- test/ngResource/resourceSpec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/ngResource/resourceSpec.js') 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); + }); }); -- cgit v1.2.3