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

Commit

Permalink
fix($resource): action defaults should override resource defaults
Browse files Browse the repository at this point in the history
defaults definned per action should take precedence over defaults
defined for the whole resource.

This is potentialy a BREAKING CHANGE in case someone relied on the buggy
behavior.
  • Loading branch information
marcenuc authored and IgorMinar committed Sep 26, 2011
1 parent 2e9fed7 commit bf5e5f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ResourceFactory.prototype = {
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
self.xhr(
action.method,
route.url(extend({}, action.params || {}, extractParams(data), params)),
route.url(extend({}, extractParams(data), action.params || {}, params)),
data,
function(status, response) {
if (response) {
Expand Down
9 changes: 9 additions & 0 deletions test/ResourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ describe("resource", function() {
nakedExpect(item).toEqual({id:'abc'});
});

it("should build resource with action default param overriding default param", function(){
xhr.expectGET('/Customer/123').respond({id:'abc'});
var TypeItem = resource.route('/:type/:typeId', {type: 'Order'},
{get: {method: 'GET', params: {type: 'Customer'}}});
var item = TypeItem.get({typeId:123});
xhr.flush();
nakedExpect(item).toEqual({id:'abc'});
});

it("should create resource", function(){
xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123, name:'misko'});

Expand Down

0 comments on commit bf5e5f7

Please sign in to comment.