Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created January 4, 2009 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lukemelia/42973 to your computer and use it in GitHub Desktop.
Save lukemelia/42973 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