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

Commit bf5e5f7

Browse files
marcenucIgorMinar
authored andcommitted
fix($resource): action defaults should override resource defaults
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.
1 parent 2e9fed7 commit bf5e5f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ResourceFactory.prototype = {
109109
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
110110
self.xhr(
111111
action.method,
112-
route.url(extend({}, action.params || {}, extractParams(data), params)),
112+
route.url(extend({}, extractParams(data), action.params || {}, params)),
113113
data,
114114
function(status, response) {
115115
if (response) {

test/ResourceSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ describe("resource", function() {
7575
nakedExpect(item).toEqual({id:'abc'});
7676
});
7777

78+
it("should build resource with action default param overriding default param", function(){
79+
xhr.expectGET('/Customer/123').respond({id:'abc'});
80+
var TypeItem = resource.route('/:type/:typeId', {type: 'Order'},
81+
{get: {method: 'GET', params: {type: 'Customer'}}});
82+
var item = TypeItem.get({typeId:123});
83+
xhr.flush();
84+
nakedExpect(item).toEqual({id:'abc'});
85+
});
86+
7887
it("should create resource", function(){
7988
xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123, name:'misko'});
8089

0 commit comments

Comments
 (0)