Skip to content

Instantly share code, notes, and snippets.

@mingca
Created October 29, 2019 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingca/574e8e4a29bbd3c7615df760c6df6129 to your computer and use it in GitHub Desktop.
Save mingca/574e8e4a29bbd3c7615df760c6df6129 to your computer and use it in GitHub Desktop.
#/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