Created
October 29, 2019 05:05
-
-
Save mingca/574e8e4a29bbd3c7615df760c6df6129 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#/spec/support/controller_helpers.rb | |
module ControllerHelpers | |
def login_devise_user(options = {}) | |
@request.env["devise.mapping"] = Devise.mappings[:user] | |
user = FactoryGirl.create(:user, options) | |
sign_in user | |
user | |
end | |
def login_omniauth_user(provider) | |
hash = build_hash(provider) | |
user = user_from_hash!(hash) | |
stub_env_for_omniauth!(provider, hash) | |
sign_in user | |
user | |
end | |
def stub_env_for_omniauth!(provider, hash) | |
OmniAuth.config.add_mock(provider, hash) | |
@request.env["devise.mapping"] = Devise.mappings[:user] | |
@request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment