Last active
December 27, 2015 09:39
-
-
Save ushu/7305078 to your computer and use it in GitHub Desktop.
tags for omniauth: @fake_google_user etc.
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
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 |
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
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 |
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
# 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 |
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
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