Logging in

33 views
Skip to first unread message

Joerg

unread,
Feb 17, 2011, 12:04:23 PM2/17/11
to Steak
Hi - I just can't seem to get my acceptance tests to log me in.

I have this in the helper:
config.include Warden::Test::Helpers, :type => :acceptance

And this before my tests ...

background :each do
@admin = Factory.create(:admin)
login_as @admin
end

There are no errors, however when I visit a URL - it sends me back to
the sign_in page ... I've run out of ideas of how to figure out why it
doesn't log me in ... So close to changing away from cucumber.

I am using Rails 3 and Rspec 2. And

warden (1.0.3)
rack (>= 1.0.0)


Thanks

David Kahn

unread,
Feb 17, 2011, 12:31:55 PM2/17/11
to ste...@googlegroups.com

Not sure if this will help you, but in acceptance/support I created a 'login_helper.rb' which takes the actions to log me in:

def login_as_valid_user
  user = Factory.create(:user)
  login_as_specific_user(user.email)
  user
end

def login_as_specific_user(email)
  user = User.find_by_email(email)
  visit('/login')
  fill_in('Email', :with => user.email)
  fill_in('Password', :with => 'Password1')
  click_button('Login')
  user
end

Then from my steak spec I can call:

login_as_valid_user   OR

login_as_specific_user(d...@structuralartistry.com)
 

Unless I am missing voodoo with Steak, you need to create these actions yourself.



Thanks

Señor J. Onion

unread,
Feb 18, 2011, 4:13:03 AM2/18/11
to ste...@googlegroups.com
Yeah I suppose that is one way to do it to go through the actual logging in process - but ideally I'd just like to set the logged in user via Warden.

It works using the Devise signin_as helpers for the controller specs. But the Steak acceptance tests I don't have access to the controller so I can't use those helpers and need to rely on the warden helpers ... but they don't seem to work as any url I visit I just get redirected to the sign in page.

Luismi Cavallé

unread,
Feb 18, 2011, 6:22:39 AM2/18/11
to ste...@googlegroups.com
Hi,

Did you check this? https://gist.github.com/549262

On the other side, doing the actual logging process might be considered a better alternative since it doesn't depend on any particular authentication system (which is an implementation detail). That's actually the approach I normally take.

-- Luismi

Señor J. Onion

unread,
Feb 18, 2011, 6:26:50 AM2/18/11
to ste...@googlegroups.com
Hi Luismi,

Yeah - I took a look at that and set up my acceptance tests like that ... But not logging me on - or keeping me logged in. Not sure which one.

I'll use your approach as an alternative, but it still irks a bit that I can't figure out why my approach isn't working ...

Joerg
Reply all
Reply to author
Forward
0 new messages