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 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',