From a12c2ece28f4b2c8c630e371865e36d6a506302f Mon Sep 17 00:00:00 2001 From: Clark Wang Date: Fri, 14 Nov 2014 15:33:29 +0800 Subject: [PATCH] Prepend slash for nested remoting paths Fix remoting paths of relation methods to correctly show in API Explorer. --- lib/model.js | 4 ++++ test/relations.integration.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/model.js b/lib/model.js index f6a3e9af..8b55c5d4 100644 --- a/lib/model.js +++ b/lib/model.js @@ -619,6 +619,10 @@ Model.nestRemoting = function(relationName, options, cb) { acceptArgs = []; } + if (httpPath[0] !== '/') { + httpPath = '/' + httpPath; + } + // A method should return the method name to use, if it is to be // included as a nested method - a falsy return value will skip. var filter = cb || options.filterMethod || function(method, relation) { diff --git a/test/relations.integration.js b/test/relations.integration.js index 25157be1..4ba459f2 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -1293,6 +1293,18 @@ describe('relations - integration', function() { }); }); + it('should have proper http.path for remoting', function() { + [app.models.Book, app.models.Image].forEach(function(Model) { + Model.sharedClass.methods().forEach(function(method) { + var http = Array.isArray(method.http) ? method.http : [method.http]; + http.forEach(function(opt) { + // destroyAll has been shared but missing http property + if (opt.path === undefined) return; + expect(opt.path, method.stringName).to.match(/^\/.*/); + }); + }); + }); + }); }); });