[rspec-users] Authenticating before tests

peter.boling peter.boling at gmail.com
Mon Sep 17 10:45:59 EDT 2007

Luke Galea-4 wrote:
> Could someone point me in the right direction?
> 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).

This is what we do.  I realize that according to the another poster this is
the wrong way, but it is the best way we've found for use with Goldberg.

  def goldbergAuthAdmin()
    get 'goldberg/auth/login'
Goldberg::User.find_by_name(:first, "admin").id)
    #Our Admin user has id 2.

BTW, another important step is bootstrapping goldberg into your test

To facilitate this we added two methods to the GoldbergMigration model:
  def self.clear_for_class(klass, dest)
    filename = "#{dest}/#{klass.to_s.sub(/^Goldberg::/, '')}.yml"
    records = klass.delete_all
  def self.clear_bootstrap
    self.goldberg_classes.each do |klass|
      self.clear_for_class klass, "#{File.dirname(__FILE__)}/../db"

Then add this to spec_helper.rb, or your own included spec_helper
  def goldbergReload()

Then call this from a before(:all) in the first describe of each rspec
needing goldberg.  Of course you have to have dumped your goldberg bootstrap
from dev/production first (You do this in the console:
"GoldbergMigration.dump_bootstrap" to save all goldberg settings,
controller/action perms, users roles, etc to some yaml files).

Hope that helps!

Peter Boling
Sagebit, LLC
View this message in context: http://www.nabble.com/Authenticating-before-tests-tf4435346.html#a12737465
Sent from the rspec-users mailing list archive at Nabble.com.

More information about the rspec-users mailing list