On Jan 16, 2011, at 9:39 PM, François Beausoleil wrote:
> Hi all,
>
> I'm trying to find out how to authenticate in functional tests. I
> can't find any information:
>
> * Agility Tutorial Functional tests are empty -
> https://github.com/tablatom/agility/tree/master/test/functional
> * Found "Full Stack Testing a HOBO Application" at
> http://conceptspace.wikidot.com/blog:all-about-testing-hobo-organizations-revisited
> which has great content, unfortunately, the #login_as helper method
> doesn't exist
>
> I also found a reference to #log_in, and simply setting session[:user]
> - none of these have any effect...
I use this in test_helper.rb:
def login_as(u)
u = users(u) if Symbol === u
@request.session[:user] = u.typed_id
end
the first line is mostly to make using fixtures easier - if you're only using
factories, you can omit it. The helper is used as follows:
def test_controller_foo_does_something
login_as(:admin)
...
end
or:
def test_controller_foo_does_something_else
u = Factory(:user)
login_as(u)
...
end
Hope this helps!
--Matt Jones
--
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.