Ups! I sent the response in a private e-mail instead of making a post
here.
---
are you testing models or controller?
If you are testing the model, you'll have to pass the user in a
method. The method shall then use:
with_acting_user(user) {
yada yada yada
}
For example:
ChampionshipControllerTest:
def test_viewable_by_admin
assert_view(:championship_with_games, :admin, true)
end
private
def assert_view(championship_label, viewing_user_label,
expected_result)
championship = championships(championship_label)
user = users(viewing_user_label)
assert_equal expected_result, championship.viewable_by?(user)
end
If you take a closer look at the viewable_by? implemented by Hobo. You
see:
(from permissions.rb)
def viewable_by?(user, attribute=nil)
...
with_acting_user(user) { view_permitted?(attribute) }
end
To test the controller, you'll have to login the user first using:
post :login, :login => 'championship_manager', :password => 'test'
TF