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

Commit 94e1c03

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 b21f4a3 commit 94e1c03

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ngResource/resource.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ angular.module('ngResource', ['ng']).
314314

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

test/ngResource/resourceSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ describe("resource", function() {
122122
});
123123

124124

125+
it('should not pass default params between actions', function() {
126+
var R = $resource('/Path', {}, {get: {method: 'GET', params: {objId: '1'}}, perform: {method: 'GET'}});
127+
128+
$httpBackend.expect('GET', '/Path?objId=1').respond('{}');
129+
$httpBackend.expect('GET', '/Path').respond('{}');
130+
131+
R.get({});
132+
R.perform({});
133+
});
134+
135+
125136
it("should build resource with action default param overriding default param", function() {
126137
$httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'});
127138
var TypeItem = $resource('/:type/:typeId', {type: 'Order'},

0 commit comments

Comments
 (0)