Skip to content

Instantly share code, notes, and snippets.

@ushu
Last active December 27, 2015 09:39
Show Gist options
  • Save ushu/7305078 to your computer and use it in GitHub Desktop.
Save ushu/7305078 to your computer and use it in GitHub Desktop.
tags for omniauth: @fake_google_user etc.
Feature: Authentication
@fake_facebook_user
Scenario: I log in with my facebook account
Given I just arrived to the Website
And I log in using facebook
Then I see the Home Page
Given(/^I just arrived to the Website$/) do
visit root_url
end
Given(/^I log in using facebook$/) do
click_link 'Facebook'
end
Then(/^I see the Home Page$/) do
current_url.should == root_url
page.should have_content('WELCOME')
end
# to be put in features/support/omniauth.rb
# mostly identical to http://pivotallabs.com/testing-omniauth-based-login-via-cucumber
# modified to generate several tags at once: @fake_twitter_user, @fake_google_user etc.
def fake_auth(user)
{
:provider => user.provider,
:uid => user.uid,
:user_info => {"email"=>user.email, "name"=>user.first_name}
}
end
%w{twitter facebook google}.each do |provider|
Before("@fake_#{provider}_user") do
@social_user = FactoryGirl.create "#{provider}_user"
OmniAuth.config.test_mode = true
provider = 'google_oauth2' if provider == 'google'
OmniAuth.config.mock_auth[provider.to_sym] = fake_auth(@social_user)
end
After("@fake_#{provider}_user") do
@social_user.destroy
OmniAuth.config.test_mode = false
end
end
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "test.user#{n}@example.com" }
factory :password_user do
password 'testpassword'
password_confirmation 'testpassword'
end
# define twitter_user, facebook_user and google_user
%w{twitter facebook google}.each do |provider|
factory "#{provider}_user" do
before :create do |user|
user.provider = (provider == 'google') ? 'googe_oauth2' : provider
user.uid = '12345'
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment