Skip to content

Commit

Permalink
Make sure options are handed down to chained policy syntax in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Feb 18, 2015
1 parent 00511b4 commit 0990fc1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/hooks/policies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},


Expand Down
29 changes: 28 additions & 1 deletion test/integration/hook.policies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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();
});
});


});

});
Expand Down

0 comments on commit 0990fc1

Please sign in to comment.