Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

add test and fix for anyone functionality #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

};
};
29 changes: 28 additions & 1 deletion test/integration/can.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,31 @@ describe('Integration: Can API', function () {

});

});
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);
});

});

});