diff --git a/lib/hooks/policies/index.js b/lib/hooks/policies/index.js index 9eb3f081c7..3a3238ef9d 100644 --- a/lib/hooks/policies/index.js +++ b/lib/hooks/policies/index.js @@ -231,7 +231,7 @@ module.exports = function(sails) { // Bind policy function to route var fn = this.lookupFn(event.target.policy, 'config.routes'); - sails.router.bind(event.path, fn, event.verb); + sails.router.bind(event.path, fn, event.verb, _.merge(event.options, event.target)); }, diff --git a/test/integration/hook.policies.test.js b/test/integration/hook.policies.test.js index 78ee2bf7df..29abe1d7e4 100644 --- a/test/integration/hook.policies.test.js +++ b/test/integration/hook.policies.test.js @@ -306,7 +306,7 @@ describe('router :: ', function() { describe('policies added inline to custom routes', function() { before(function() { - var config = 'module.exports.routes = {"get /testPol": [{policy: "error_policy"}]}'; + var config = 'module.exports.routes = {"get /*": [{policy: "error_policy", skipRegex: /^\\/foo.*$/}], "get /foobar": function(req, res){return res.send("ok!");}}'; fs.writeFileSync(path.resolve('../', appName, 'config/routes.js'), config); }); @@ -336,6 +336,33 @@ describe('router :: ', function() { }); }); + it ('should respect options', function(done) { + httpHelper.testRoute('get', { + url: 'foobar', + headers: { + 'Content-Type': 'application/json' + }, + json: true + }, function(err, response) { + if (err) return done(err); + + try { + // Assert HTTP status code is correct + assert.equal(response.statusCode, 200); + + // Assert that response has the proper error message + assert.equal(response.body, 'ok!'); + + } + catch (e) { + return done(e); + } + + return done(); + }); + }); + + }); });