From 823c83b41b95f1f5da1c5736d939b5c3e2eba061 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Tue, 15 Mar 2016 11:45:34 -0500 Subject: [PATCH 1/2] Allow use of `fn` in route targets (same usage as `target`) Also added tests for both --- lib/router/bind.js | 4 ++-- test/unit/router.bind.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/router/bind.js b/lib/router/bind.js index 6286f3fd56..b0b9a86dc9 100644 --- a/lib/router/bind.js +++ b/lib/router/bind.js @@ -55,8 +55,8 @@ function bind( /* path, target, verb, options */ ) { // If target is an object with a `target`, pull out the rest // of the keys as route options and then bind the target. - else if (_.isPlainObject(target) && target.target) { - var _target = target.target; + else if (_.isPlainObject(target) && (target.target || target.fn)) { + var _target = target.target || target.fn; options = _.merge(options, _.omit(target, 'target')); bind.apply(this, [path, _target, verb, options]); } diff --git a/test/unit/router.bind.test.js b/test/unit/router.bind.test.js index 894733f4c5..cb6b3cf827 100644 --- a/test/unit/router.bind.test.js +++ b/test/unit/router.bind.test.js @@ -30,6 +30,34 @@ describe('Router.bind', function() { }); }); + $Router.bind('get /footarg', {target: RESPOND.HELLO}) + .expectBoundRoute({ + path: '/footarg', + method: 'get' + }) + .test(function() { + it('should send expected response (get /footarg)', function(done) { + supertest(this.sails.router._privateRouter) + .get('/foo') + .expect(200, 'hello world!') + .end(done); + }); + }); + + $Router.bind('get /foofn', {fn: RESPOND.HELLO}) + .expectBoundRoute({ + path: '/foofn', + method: 'get' + }) + .test(function() { + it('should send expected response (get /foofn)', function(done) { + supertest(this.sails.router._privateRouter) + .get('/foo') + .expect(200, 'hello world!') + .end(done); + }); + }); + $Router.bind('/bar', RESPOND.HELLO) .expectBoundRoute({ path: '/bar', From df7b0c53ef2fc86f03f10667a3db87043501ea8a Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Tue, 15 Mar 2016 11:47:42 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cc65caac..04ddb6ae7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Master +* [ENHANCEMENT] Allow use of `fn` in expanded route targets [e1790b7](https://github.com/balderdashy/sails/commit/e1790b70b35cd7dc50743a63bb169585f8a927f2) * [BUGFIX] Add blacklist to "update" blueprint action so that it can be used with primary keys that are not "id" [3625](https://github.com/balderdashy/sails/issues/3625) * [ENHANCEMENT] Allow hooks to be turned off by setting their environment var to the string "false" [3618](https://github.com/balderdashy/sails/issues/3618) * [BUGFIX] Allow view target syntax for routes to specify deeply-nested views [3604](https://github.com/balderdashy/sails/issues/3604) @@ -16,7 +17,7 @@ * [INTERNAL] Force asynchronicity in the optional third argument of `res.view()`/`res.render()` to pave the way for better, request-agnostic view rendering methods. This prevents double-calling of the callback if userland code throws an error. Thanks [@lennym](https://github.com/lennym)! [cd413e15435947aa855e27aab16d9cd9e65ad493](https://github.com/balderdashy/sails/commit/cd413e15435947aa855e27aab16d9cd9e65ad493) * [ENHANCEMENT] Improve auto-migrate prompt, and skip the prompt and log an info message instead if `sails.config.models.migrate` is being automatically set to production anyways. [sails-hook-orm/commit/3161c34edbe0aa07055f8665493734dda1688c2a](https://github.com/balderdashy/sails-hook-orm/commit/3161c34edbe0aa07055f8665493734dda1688c2a) * [ENHANCEMENT] Add production check in case sails-disk is being used, and experimental `sails.config.orm.skipProductionWarnings` flag for preventing the warning. [sails-hook-orm/commit/9a0d46e135dadf00bc4576341624a31e50b12838](https://github.com/balderdashy/sails-hook-orm/commit/9a0d46e135dadf00bc4576341624a31e50b12838) - +* [INTERNAL] Don't clone target function in expanded route syntax [6cfb2de](https://github.com/balderdashy/sails/commit/6cfb2de17ccafd789d4af001934b286bc189d1a4) ### 0.12.1