On 13.9.2007, at 15.25, Luke Galea wrote:

Hi all,

I'm using Goldberg, an engine that provides roles based access
control for my app. I need to login before I can do controller tests,
but I can't find any examples of people doing this.

Could someone point me in the right direction?

This is what we do:

in spec_helper.rb:

  include AuthenticatedTestHelper

  def login_as(user)
    controller.send :current_user=, user
  end

Then, in a before(:all) block, I can say login_as(@user) with a user object. This assumes you're using restful_authentication (and should work with acts_as_authenticated as well).


I thought the simplest way would be to either call the login action
from my other tests before(:all), but I can't seem to find how to
call another controller from within the spec for a different
controller. (Results in @controller is nil).

You can't and shouldn't do that. Just find out how your particular authentication system determines the login and create a helper method like login_as above to simulate the login.

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to