Skip to content

Commit c6d9d49

Browse files
author
Michael Leaney
committed
1 parent 5546e8e commit c6d9d49

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/restangular.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,24 +1242,23 @@ module.provider('Restangular', function() {
12421242
}
12431243

12441244
function addRestangularMethodFunction(name, operation, path, defaultParams, defaultHeaders, defaultElem) {
1245-
var bindedFunction;
1245+
var newRestangularObject,
1246+
createdFunction;
1247+
12461248
if (operation === 'getList') {
1247-
bindedFunction = _.bind(fetchFunction, this, path);
1249+
newRestangularObject = this.all(path);
12481250
} else {
1249-
bindedFunction = _.bind(customFunction, this, operation, path);
1251+
newRestangularObject = this.one(path);
12501252
}
12511253

1252-
var createdFunction = function(params, headers, elem) {
1253-
var callParams = _.defaults({
1254-
params: params,
1255-
headers: headers,
1256-
elem: elem
1257-
}, {
1258-
params: defaultParams,
1259-
headers: defaultHeaders,
1260-
elem: defaultElem
1261-
});
1262-
return bindedFunction(callParams.params, callParams.headers, callParams.elem);
1254+
createdFunction = function(params, headers, elem) {
1255+
var params, headers, elem;
1256+
1257+
params = _.defaults(params, defaultParams);
1258+
headers = _.defaults(headers, defaultHeaders);
1259+
elem = _.defaults(elem, defaultElem);
1260+
1261+
return newRestangularObject[operation](params, headers, elem);
12631262
};
12641263

12651264
if (config.isSafe(operation)) {

test/restangularSpec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe("Restangular", function() {
22
// API
33
var Restangular, $httpBackend;
4-
var accountsModel, restangularAccounts, restangularAccount0, restangularAccount1;
4+
var accountsModel, restangularAccounts, restangularAccount0, restangularAccount1, fooModel;
55
var accountsHalModel;
66
var messages, newAccount;
77

@@ -27,7 +27,11 @@ describe("Restangular", function() {
2727

2828
infoModel = {
2929
id: 0, text: "Some additional account information"
30-
}
30+
};
31+
32+
fooModel = {
33+
foo: 'bar'
34+
};
3135

3236
newAccount = {id: 44, user: "First User", amount: 45, transactions: []};
3337

@@ -43,6 +47,7 @@ describe("Restangular", function() {
4347

4448
$httpBackend.whenGET("/accounts").respond(accountsModel);
4549
$httpBackend.whenGET("/accounts/do-something").respond(accountsDoSomethingModel);
50+
$httpBackend.whenGET("/accounts/do-something/foo").respond(fooModel);
4651
$httpBackend.whenJSONP("/accounts").respond(accountsModel);
4752
$httpBackend.whenGET("/accounts/0,1").respond(accountsModel);
4853
$httpBackend.whenGET("/accounts/messages").respond(messages);

0 commit comments

Comments
 (0)