Skip to content

Commit

Permalink
Allow hooks to be turned off by setting their environment var to the …
Browse files Browse the repository at this point in the history
…string "false"

closes #3618
  • Loading branch information
sgress454 committed Feb 29, 2016
1 parent 420986a commit 75e3e13
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/app/private/loadHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(sails) {
var hookPrototype = hooks[id];

// Allow disabling of hooks by setting them to "false"
if (hookPrototype === false || hooks[id.split('.')[0]] === false) {
if (hookPrototype === false || hookPrototype === 'false' || hooks[id.split('.')[0]] === false) {
delete hooks[id];
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ module.exports = function(sails) {
hookName = identity.replace(/^(@.+?\/)?(sails-hook-)?/, '');
}

if (sails.config.hooks[hookName] === false) {
if (sails.config.hooks[hookName] === false || sails.config.hooks[hookName] === 'false') {
return memo;
}

Expand Down
49 changes: 49 additions & 0 deletions test/integration/hook.3rdparty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,55 @@ describe('hooks :: ', function() {

});

describe('with hooks.shout set to boolean false', function() {

var sails;

before(function(done) {
appHelper.liftQuiet({hooks: {shout: false}}, function(err, _sails) {
if (err) {return done(err);}
sails = _sails;
return done();
});
});

after(function(done) {
sails.lower(function(){setTimeout(done, 100);});
});

it('should not install a hook into `sails.hooks.shout`', function() {

assert(_.isUndefined(sails.hooks.shout));

});

});


describe('with hooks.shout set to the string "false"', function() {

var sails;

before(function(done) {
appHelper.liftQuiet({hooks: {shout: "false"}}, function(err, _sails) {
if (err) {return done(err);}
sails = _sails;
return done();
});
});

after(function(done) {
sails.lower(function(){setTimeout(done, 100);});
});

it('should not install a hook into `sails.hooks.shout`', function() {

assert(_.isUndefined(sails.hooks.shout));

});

});

describe('with hook-level config options', function() {

var sails;
Expand Down
23 changes: 23 additions & 0 deletions test/unit/app.initializeHooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ describe('app.initializeHooks()', function() {
});
});

describe('with the grunt hook set to boolen false', function() {
var sails = $Sails.load({hooks: {grunt: false}});
it('should expose hooks on the `sails` global', function() {
sails.hooks.should.be.an.Object;
});
it('should expose all the core hooks except for Grunt', function() {
var intersection = _.intersection(_.keys(sails.hooks), _.keys(constants.EXPECTED_DEFAULT_HOOKS));
assert.deepEqual(intersection, _.without(_.keys(constants.EXPECTED_DEFAULT_HOOKS), 'grunt'), 'Missing expected default hooks');
});
});

describe('with the grunt hook set to the string "false"', function() {
var sails = $Sails.load({hooks: {grunt: "false"}});
it('should expose hooks on the `sails` global', function() {
sails.hooks.should.be.an.Object;
});
it('should expose all the core hooks except for Grunt', function() {
var intersection = _.intersection(_.keys(sails.hooks), _.keys(constants.EXPECTED_DEFAULT_HOOKS));
assert.deepEqual(intersection, _.without(_.keys(constants.EXPECTED_DEFAULT_HOOKS), 'grunt'), 'Missing expected default hooks');
});
});




describe('configured with a custom hook called `noop`', function() {
Expand Down

0 comments on commit 75e3e13

Please sign in to comment.