diff --git a/lib/resolver.js b/lib/resolver.js index b78945d..9b93125 100644 --- a/lib/resolver.js +++ b/lib/resolver.js @@ -41,8 +41,8 @@ module.exports = { rules: function (rules, user, method) { return (rules || []) .filter(function (rule) { - return rule.user === user && rule.method === method; + return (!rule.user || rule.user === user) && rule.method === method; }); } -}; \ No newline at end of file +}; diff --git a/test/integration/can.js b/test/integration/can.js index 8ee67b5..4599e2b 100644 --- a/test/integration/can.js +++ b/test/integration/can.js @@ -281,4 +281,31 @@ describe('Integration: Can API', function () { }); -}); \ No newline at end of file + describe('Anyone', function() { + var doctor; + var drHouse, drJeckyl, patient; + beforeEach(function () { + drJeckyl = new Doctor(); + drHouse = new Doctor(); + patient = new Patient(); + Patient.authorize.anyone.to.read.when(function (genericUser) { + return this.appointments.filter(function (appointment) { + return appointment.doctor === genericUser; + }); + }); + patient.appointments = [{doctor: drHouse}]; + }); + + it('allows anyone with proper permissions to read', function() { + return expect(drHouse.can.read(patient)) + .to.eventually.equal(null); + }); + + it('rejects anyone without proper permissions', function() { + return expect(drJeckyl.can.read(patient)) + .to.be.rejectedWith(AuthorizationError); + }); + + }); + +});