From 41713cebefc4a08858a8c32960a30e2377fbfa7d Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo Date: Thu, 27 Feb 2014 18:46:34 +0100 Subject: [PATCH] fix($resource): functions in params should not be executed if overridden --- src/ngResource/resource.js | 9 +++++---- test/ngResource/resourceSpec.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index dd6062e6b215..55f107bb692b 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -557,10 +557,11 @@ angular.module('ngResource', ['ng']). } }); - if (hasBody) httpConfig.data = data; - route.setUrlParams(httpConfig, - extend({}, extractParams(data, action.params || {}), params), - action.url); + if (hasBody) httpConfig.data = data; + params = extend({}, action.params || {}, params); + route.setUrlParams(httpConfig, + extractParams(data, params), + action.url); var promise = $http(httpConfig).then(function (response) { var data = response.data, diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index 6e58976355bd..310c8e75a8eb 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -380,6 +380,17 @@ describe("resource", function() { inst.$post(); }); + it('should not call function in action param if overriden', function() { + $httpBackend.expect('GET', '/item/123').respond({foo: 'bar'}); + + var TypeItem = $resource('/item/:id', {}, {get: {method: 'GET', params: {id: callback}}}); + var item = TypeItem.get({id: 123}); // overrides params.id + + $httpBackend.flush(); + + expect(callback).not.toHaveBeenCalled(); + expect(item).toEqualData({foo: 'bar'}); + }); it('should not throw TypeError on null default params', function() { $httpBackend.expect('GET', '/Path').respond('{}');