Hi
Has anybody got a sample of a controller test file (ideally with  
shoulda) that shows how the
login action is performed so that the subsequient get/post action is  
done in a logged in state.
I am particularly interested how to set up the user in the tests. (not  
via Fixtures)

My current setup is here,   http://gist.github.com/45694 but the tests  
do not work when the veiwable
restrictions are set to more complex things than a simple true  
(everybody can view)

I would like to set up the tests as there are different roles in the  
app and I think doing
controller tests would be the best place to put in the desired results.

Thanx

Am 09.01.2009 um 22:34 schrieb Tiago Franco:

>
> 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
>
> On Jan 9, 8:20 pm, Steve DeBaun <[email protected]> wrote:
>> I want to be able to set acting_user to a specific user during a
>> test.  Can this be done easily?
>>
>> Cheers,
>>
>> sd
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to