From df276536abf2377e23f2e165bb270d4d5d0678a6 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Tue, 17 Nov 2009 10:33:03 -0800 Subject: [PATCH] adding documentation for testing abilities - closes #6 --- README.rdoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.rdoc b/README.rdoc index 53edaf1..218c9f9 100644 --- a/README.rdoc +++ b/README.rdoc @@ -191,6 +191,18 @@ For example, let's assume that each user has_many :permissions, and each permiss The actual details will depend largely on your application requirements, but hopefully you can see how it's possible to define permissions in the database and use them with CanCan. +== Testing Abilities + +It is very easy to test the Ability model since you can call "can?" directly on it as you would in the view or controller. + +def test "user can only destroy projects which he owns" + user = User.new + ability = Ability.new(user) + assert ability.can?(:destroy, Project.new(:user => user)) + assert !ability.can?(:destroy, Project.new) +end + + == Special Thanks CanCan was inspired by declarative_authorization[http://github.com/stffn/declarative_authorization/] and aegis[http://github.com/makandra/aegis]. Many thanks to the authors and contributors.