# Controller Testing and Role Based Access Control

**URL:** <https://www.ruby-forum.com/t/controller-testing-and-role-based-access-control/138631>\
**Category:** Rails\
**Created:** [May 26, 2008, 5:53am UTC](https://www.ruby-forum.com/t/controller-testing-and-role-based-access-control/138631 "2008-05-26T05:53:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [May 26, 2008, 5:53am UTC](https://www.ruby-forum.com/t/controller-testing-and-role-based-access-control/138631/1 "2008-05-26T05:53:47Z")

</div>

I think I have a handle on Unit testing and have set up tests for  
approximately 20 of my models. I’m now fooling with Controller testing  
and still following the AWDWR book with some success.

I have a Role Based Access Control system…pretty much conceived from  
Chad F.'s Rails Recipes that I’ve been using for some time now and I  
can login and pass the following assertions…

assert\_redirected\_to :controller =\> ‘main\_tabnav’

# the redirect from a successful login

assert\_not\_nil(session[:user\_id])  
user = User.find(session[:user\_id])  
assert\_equal ‘Low Level User’, user.name

So I’ve created 3 Users in users.yml which will give me 3 levels of RBAC  
testing and created the roles\_users.yml One of my main purposes for  
doing integrated testing is to test out my users/rights/roles mechanics  
since I now have over 1500 ‘rights’ and 60 ‘roles’

My question is one of practical design…

If I want to set up controller tests for which I can plug in 3 different  
users and obviously anticipate different results for each user, how can  
I accomplish this without creating 3 different test sets for each  
controller?

Craig
