This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'test_helper' | ||
|
||
class AuthorizationsControllerTest < ActionController::TestCase | ||
fixtures :all | ||
|
||
setup do | ||
OmniAuth.config.test_mode = true | ||
end | ||
|
||
|
||
|
||
test 'should create new authorization and log in' do | ||
|
||
set_ommniauth | ||
|
||
get :create | ||
|
||
user = UserSession.find.record | ||
assert_redirected_to user_path(user) | ||
end | ||
|
||
test 'should find existing authorization and log in' do | ||
quentin = users(:quentin) | ||
Authorization.create_from_hash(auth_hash(quentin.email), quentin) | ||
set_ommniauth(quentin.email) | ||
|
||
get :create | ||
|
||
assert_redirected_to user_path(quentin) | ||
end | ||
|
||
test 'should authorize existing logged-in user' do | ||
quentin = users(:quentin) | ||
login_as :quentin | ||
|
||
set_ommniauth(quentin.email) | ||
|
||
get :create | ||
|
||
assert_redirected_to user_path(quentin) | ||
end | ||
|
||
|
||
def set_ommniauth(email=nil) | ||
OmniAuth.config.mock_auth[:facebook] = auth_hash(email) | ||
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook] | ||
end | ||
|
||
def auth_hash(email='email@example.com') | ||
{ | ||
'provider' => 'facebook', | ||
"info" => { | ||
'nickname' => 'Omniauth-user', | ||
'email' => email | ||
}, | ||
'uid' => '123545' | ||
} | ||
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
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