Skip to content

Commit c0de8fb

Browse files
deviousdodoIgorMinar
authored andcommitted
fix($resource): prevent default params to be shared between actions
Having a $resource defined as: var R = $resource('/Path', {}, { get: {method: 'GET', params: {objId: '1'}}, perform: {method: 'GET'} }); was causing both actions to call the same URI (if called in this order): R.get({}); // => /Path?objId=1 R.perform({}); // => /Path?objId=1
1 parent 557e389 commit c0de8fb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ngResource/resource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ angular.module('ngResource', ['ng']).
313313

314314
function extractParams(data, actionParams){
315315
var ids = {};
316-
paramDefaults = extend(paramDefaults, actionParams);
317-
forEach(paramDefaults || {}, function(value, key){
316+
actionParams = extend({}, paramDefaults, actionParams);
317+
forEach(actionParams, function(value, key){
318318
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
319319
});
320320
return ids;

test/ngResource/resourceSpec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ describe("resource", function() {
115115
});
116116

117117

118+
it('should not pass default params between actions', function() {
119+
var R = $resource('/Path', {}, {get: {method: 'GET', params: {objId: '1'}}, perform: {method: 'GET'}});
120+
121+
$httpBackend.expect('GET', '/Path?objId=1').respond('{}');
122+
$httpBackend.expect('GET', '/Path').respond('{}');
123+
124+
R.get({});
125+
R.perform({});
126+
});
127+
128+
118129
it("should build resource with action default param overriding default param", function() {
119130
$httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'});
120131
var TypeItem = $resource('/:type/:typeId', {type: 'Order'},

0 commit comments

Comments
 (0)