angular/angular.js — pull request #1593 by freshtonic (2012-11-20 07:04:09+00:00)
Title: Don't clobber paramDefaults in ngResource actions

The 'paramDefaults' parameter is global to a resource created by $resource. The
'extractParams' function was merging 'actionParams' into it every time when it
really should be creating a new object that is a merge of paramDefaults and
actionParams. paramDefaults itself should remain unchanged.

The following code proves the issue (it's a negative test I didn't add a spec for it).

it('should not clobber paramDefaults', function() {

var R = $resource('/Customer/:id/:otherActionParam',
{id: '@id'}, {otherAction: {method: 'POST', params: {otherActionParam: 'other-action-says-hi'}}});

var thing = new R({id:123});

$httpBackend.expect('POST', '/Customer/123/other-action-says-hi').respond();
thing.$otherAction();
$httpBackend.flush();

// This expectation fails because other-action-says-hi is still here.
$httpBackend.expect('POST', '/Customer/123').respond();
thing.$save();
$httpBackend.flush();
});