Skip to content

Instantly share code, notes, and snippets.

@cheald
Created November 23, 2012 08:11
Show Gist options
  • Save cheald/4134479 to your computer and use it in GitHub Desktop.
Save cheald/4134479 to your computer and use it in GitHub Desktop.
module AuthenticationHelpers
def authenticated_as(roles, options=nil)
options = instance_eval(&options) if options.is_a? Proc
Array(roles).each do |role|
context "when logged in as a #{role}" do
before(:all) { @user = FactoryGirl.create role, *Array(options) }
after(:all) { DatabaseCleaner.clean }
before(:each) { sign_in @user }
after(:each) { sign_out @user }
yield if block_given?
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment