-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mastilver/nested-factories
support nested factories
- Loading branch information
Showing
9 changed files
with
199 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
module.exports.policiesArgs = function(req, res){ | ||
res.ok(); | ||
}; | ||
|
||
module.exports.mixedArgs = function(req, res){ | ||
res.ok(); | ||
}; | ||
|
||
module.exports.factoriesArgs = function(req, res){ | ||
res.ok(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require('should'); | ||
var request = require('supertest'); | ||
|
||
var Sails = require('sails').Sails; | ||
|
||
|
||
describe('parametized policies hook - nested factories', function(){ | ||
|
||
var sails; | ||
|
||
before(function(done){ | ||
|
||
|
||
this.timeout(11000); | ||
|
||
Sails().lift({ | ||
hooks: { | ||
'parametized-policies': require('../'), | ||
grunt: false, | ||
}, | ||
log: { | ||
level: 'error' | ||
}, | ||
paths: { | ||
controllers: __dirname + '/controllers', | ||
policies: __dirname + '/policies', | ||
policiesFactories: __dirname + '/policiesFactories', | ||
}, | ||
routes: { | ||
'GET /policies-args': 'NestedController.policiesArgs', | ||
'GET /mixed-args': 'NestedController.mixedArgs', | ||
'GET /factories-args': 'NestedController.factoriesArgs', | ||
}, | ||
policies: { | ||
'NestedController': { | ||
'policiesArgs': ['and(isAdmin, accept)'], | ||
'mixedArgs': 'and(isAdmin, is(\'User\'))', | ||
'factoriesArgs': 'and(is(\'Admin\'), is(\'User\'))', | ||
} | ||
} | ||
}, function(err, _sails){ | ||
|
||
if(err) return done(err); | ||
|
||
sails = _sails; | ||
|
||
return done(); | ||
}); | ||
}); | ||
|
||
after(function(done){ | ||
|
||
if(sails){ | ||
sails.lower(done); | ||
} | ||
|
||
}); | ||
|
||
it('should start the sails server', function(){ | ||
return true; | ||
}); | ||
|
||
it('should handle factory with policies as arguments', function(done){ | ||
request(sails.hooks.http.app) | ||
.get('/policies-args') | ||
.expect('Admin', done); | ||
}); | ||
|
||
it('should handle factory with mixed arguments', function(done){ | ||
request(sails.hooks.http.app) | ||
.get('/mixed-args') | ||
.expect('AdminUser', done); | ||
}); | ||
|
||
it('should handle factory with factories as arguments', function(done){ | ||
request(sails.hooks.http.app) | ||
.get('/factories-args') | ||
.expect('AdminUser', done); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
module.exports = function(req, res, next){ | ||
|
||
res.write('Admin'); | ||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
module.exports = function(firstFn, secondFn){ | ||
|
||
return function(req, res, next){ | ||
|
||
firstFn(req, res, function(){ | ||
|
||
secondFn(req, res, next); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function(json){ | ||
return function(req, res, next){ | ||
res.write(JSON.parse(json)[0]); | ||
next(); | ||
}; | ||
}; |