Skip to content

Instantly share code, notes, and snippets.

@timfjord
Created November 5, 2012 17:25
Show Gist options
  • Save timfjord/4018540 to your computer and use it in GitHub Desktop.
Save timfjord/4018540 to your computer and use it in GitHub Desktop.
module HelperMacros
extend ActiveSupport::Concern
module ClassMethods
# Use before test block 'it'
# create global object user and sign in
#
def sign_in(who=:user)
let(:current_user) { FactoryGirl.create(who) }
before(:each) { sign_in current_user }
end
end
# Use in test block 'it'
# sign in with customize user or guest (use in 'it')
#
def sign_in(user)
visit login_path
unless current_path == login_path
sign_out
end
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:google_oauth2, {
provider: 'google',
uid: user.token,
info: {
first_name: user.firstname,
last_name: user.lastname,
email: user.email
}
})
if user.guest
fill_in "user[login]", with: user.login
fill_in "user[password]", with: 'password'
click_button 'Login'
else
click_link 'Login with Google'
end
end
def sign_out
visit root_path
click_link 'Logout'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment