Skip to content

Instantly share code, notes, and snippets.

@jaigouk
Forked from lukemelia/gist:42973
Created February 19, 2009 10:34
Show Gist options
  • Save jaigouk/66849 to your computer and use it in GitHub Desktop.
Save jaigouk/66849 to your computer and use it in GitHub Desktop.
#features/steps/users_steps.rb:
Given "I'm a logged in member" do
@me = create_adult
logged_in_as @me
end
#features/support/env.rb:
class Cucumber::Rails::World
...
def logged_in_as(user)
cookies['integration_test_user'] = user.id.to_s
end
...
end
#app/controllers/application.rb
class ApplicationController < ActionController::Base
...
before_filter :login_integration_test_user, :if => lambda { Rails.env == 'test' }
...
def login_integration_test_user
return true if cookies['integration_test_user'].blank?
integration_test_user_id = cookies['integration_test_user'].to_i
if integration_test_user_id != current_user.id
reset_session
self.current_user = User.find(integration_test_user_id)
end
cookies['integration_test_user'] = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment