End of train commit
This commit is contained in:
@@ -20,6 +20,7 @@ class UserController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def obtain_token
|
def obtain_token
|
||||||
|
redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.json do
|
format.json do
|
||||||
|
|||||||
+3
-2
@@ -28,14 +28,15 @@ class User
|
|||||||
|
|
||||||
def self.find_for_facebook_oauth(auth_data, user)
|
def self.find_for_facebook_oauth(auth_data, user)
|
||||||
user = database.view(self.by_facebook(key: [auth_data.provider, auth_data.uid], limit: 1)).first
|
user = database.view(self.by_facebook(key: [auth_data.provider, auth_data.uid], limit: 1)).first
|
||||||
|
|
||||||
user || create(
|
user || create(
|
||||||
provider: auth_data.provider,
|
provider: auth_data.provider,
|
||||||
uid: auth_data.uid,
|
uid: auth_data.uid,
|
||||||
name: auth_data.info.nickname,
|
name: auth_data.info.nickname,
|
||||||
email: auth_data.info.email,
|
email: auth_data.info.email,
|
||||||
password: Devise.friendly_token[0,20],
|
password: Devise.friendly_token[0,20],
|
||||||
oauth_token: user.oauth_token = auth.credentials.token,
|
oauth_token: auth_data.credentials.token,
|
||||||
oauth_expires_at: Time.at(auth_data.credentials.expires_at),
|
oauth_expires_at: auth_data.credentials.expires ? Time.at(auth_data.credentials.expires_at) : nil,
|
||||||
auth_data: auth_data
|
auth_data: auth_data
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
Feature: Sign up as user using facebook
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Happy flow
|
||||||
|
Given There is no user information stored in the local storage
|
||||||
|
When I visit the user obtain token path
|
||||||
|
Then I should be signed in as a user
|
||||||
|
And I should be redirected to the user home
|
||||||
|
And the newly created user info should be stored in the local storage
|
||||||
|
|
||||||
|
@broken
|
||||||
|
Scenario: Already signed in user visits obtain token path
|
||||||
|
Given I am signed in as a user
|
||||||
|
And There is no user information stored in the local storage
|
||||||
|
Then I should be redirected to the user home
|
||||||
|
And the newly created user info should be stored in the local storage
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
step "There is no user information stored in the local storage" do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
step "I visit the user obtain token path" do
|
||||||
|
visit user_obtain_token_path
|
||||||
|
end
|
||||||
|
|
||||||
|
step "I should be signed in as a user" do
|
||||||
|
@user = User.find_by_oauth_token 'fbAuthToken234'
|
||||||
|
page.evaluate_script(%|Qstorage.getItem('user_id')|).should == @user.id
|
||||||
|
page.evaluate_script(%|Qstorage.getItem('auth_token')|).should == @user.authentication_token
|
||||||
|
binding.pry
|
||||||
|
end
|
||||||
|
|
||||||
|
step "I should be redirected to the user home" do
|
||||||
|
|
||||||
|
end
|
||||||
|
step "the newly created user info should be stored in the local storage" do
|
||||||
|
|
||||||
|
end
|
||||||
@@ -41,6 +41,21 @@ RSpec.configure do |config|
|
|||||||
config.filter_run_excluding broken: true
|
config.filter_run_excluding broken: true
|
||||||
config.render_views = true
|
config.render_views = true
|
||||||
|
|
||||||
|
OmniAuth.config.test_mode = true
|
||||||
|
OmniAuth.config.add_mock :facebook, {
|
||||||
|
info: {
|
||||||
|
nickname: 'Joey',
|
||||||
|
name: "Facebook Joe",
|
||||||
|
first_name: "Facebook Joe"
|
||||||
|
},
|
||||||
|
credentials: {
|
||||||
|
'token' => 'fbAuthToken234',
|
||||||
|
'expires_at' => 1.week.from_now.to_i,
|
||||||
|
'expires' => true
|
||||||
|
},
|
||||||
|
uid: '123456790'
|
||||||
|
}
|
||||||
|
|
||||||
# Use color in STDOUT
|
# Use color in STDOUT
|
||||||
config.color_enabled = true
|
config.color_enabled = true
|
||||||
config.fail_fast = false
|
config.fail_fast = false
|
||||||
|
|||||||
Reference in New Issue
Block a user