Skip to content

Commit

Permalink
- fix related to the issue angular#875
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovalex committed May 11, 2012
1 parent a931154 commit 5e8ead2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ angular.module('ngResource', ['ng']).

actions = extend({}, DEFAULT_ACTIONS, actions);

function extractParams(data){
function extractParams(data, actionParams){
var ids = {};
paramDefaults = extend(paramDefaults, actionParams);
forEach(paramDefaults || {}, function(value, key){
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
});
Expand Down Expand Up @@ -366,7 +367,7 @@ angular.module('ngResource', ['ng']).
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
$http({
method: action.method,
url: route.url(extend({}, extractParams(data), action.params || {}, params)),
url: route.url(extend({}, extractParams(data, action.params || {}), params)),
data: data
}).then(function(response) {
var data = response.data;
Expand Down
11 changes: 11 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ describe("resource", function() {
});


it('should build resource with action default param reading the value from instance', function() {
$httpBackend.expect('POST', '/Customer/123').respond();
var R = $resource('/Customer/:id', {}, {post: {method: 'POST', params: {id: '@id'}}});

var inst = new R({id:123});
expect(inst.id).toBe(123);

inst.$post();
});


it('should handle multiple params with same name', function() {
var R = $resource('/:id/:id');

Expand Down

0 comments on commit 5e8ead2

Please sign in to comment.