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

Commit

Permalink
fix($resource): prevent default params to be shared between actions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
deviousdodo authored and IgorMinar committed Nov 24, 2012
1 parent b21f4a3 commit 94e1c03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ angular.module('ngResource', ['ng']).

function extractParams(data, actionParams){
var ids = {};
paramDefaults = extend(paramDefaults, actionParams);
forEach(paramDefaults || {}, function(value, key){
actionParams = extend({}, paramDefaults, actionParams);
forEach(actionParams, function(value, key){
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
});
return ids;
Expand Down
11 changes: 11 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ describe("resource", function() {
});


it('should not pass default params between actions', function() {
var R = $resource('/Path', {}, {get: {method: 'GET', params: {objId: '1'}}, perform: {method: 'GET'}});

$httpBackend.expect('GET', '/Path?objId=1').respond('{}');
$httpBackend.expect('GET', '/Path').respond('{}');

R.get({});
R.perform({});
});


it("should build resource with action default param overriding default param", function() {
$httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'});
var TypeItem = $resource('/:type/:typeId', {type: 'Order'},
Expand Down

0 comments on commit 94e1c03

Please sign in to comment.