Created
November 5, 2012 17:25
-
-
Save timfjord/4018540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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