Skip to content

Commit 5546e8e

Browse files
author
Michael Leaney
committed
Add a test for nested resources from a addRestangularMethod result
This test identifies an issue I am currently having with `addRestangularMethod`. Given the following code. ```js var Accounts = Restangular.withConfig(function(RestangularConfigurer) { RestangularConfigurer.addElementTransformer('users', true, function(worker) { worker.addRestangularMethod('doSomething', 'get', 'do-something'); return worker; }); }).service('accounts'); Accounts.doSomething().then(function(doSomething) { doSomething.one('foo').get(); }); ``` I would expect `doSomething.one('foo').get()` to fetch `accounts/do-something/foo`, and not `accounts/foo`.
1 parent 91be864 commit 5546e8e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/restangularSpec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,26 @@ describe("Restangular", function() {
609609
});
610610
});
611611

612+
it("should have the correct url when using addRestangularMethod", function() {
613+
var Accounts = Restangular.withConfig(function(RestangularConfigurer) {
614+
RestangularConfigurer.addElementTransformer('accounts', true, function(worker) {
615+
worker.addRestangularMethod('doSomething', 'get', 'do-something');
616+
return worker;
617+
});
618+
}).service('accounts');
619+
620+
expect(Accounts.doSomething).toBeDefined();
621+
expect(_.isFunction(Accounts.doSomething)).toBeTruthy();
622+
623+
Accounts.doSomething().then(function(doSomething) {
624+
doSomething.one('foo').get();
625+
});
626+
627+
$httpBackend.expectGET('/accounts/do-something');
628+
$httpBackend.expectGET('/accounts/do-something/foo');
629+
$httpBackend.flush();
630+
});
631+
612632
describe("ONE", function() {
613633
it("get() should return a JSON item", function() {
614634
restangularAccount1.get().then(function(account) {

0 commit comments

Comments
 (0)