Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
add test on bug and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PanfilovDenis committed Apr 4, 2013
1 parent 0b1512e commit 868a9b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/controllers/web/social_networks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ def facebook

authorization = Authorization.find_by_provider_and_uid(auth_hash[:provider], auth_hash[:uid])

if authorization && !authorization.user.inactive?
if authorization

if authorization.user.inactive?
flash_error
redirect_to root_path
return
end

sign_in authorization.user
flash_success
else
Expand Down
26 changes: 26 additions & 0 deletions test/functional/web/social_networks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class Web::SocialNetworksControllerTest < ActionController::TestCase
assert_equal current_user, @user
end

test "should fail authorization with facebook" do
@user.deactivate
@user.authorizations << build_authorization(@auth_hash)
@user.save

request.env['omniauth.auth'] = @auth_hash
get :facebook

assert_response :redirect
assert !signed_in?
end

test "should get authorization with facebook on existing user" do
@user.email = @auth_hash[:info][:email]
@user.save
Expand All @@ -43,6 +55,20 @@ class Web::SocialNetworksControllerTest < ActionController::TestCase
assert session_auth_hash
end

test "should fail authorization with facebook on inactive user" do
@user.email = @auth_hash[:info][:email]
@user.deactivate

request.env['omniauth.auth'] = @auth_hash
get :facebook

assert_response :redirect
@user.reload
assert @user.inactive?
assert !signed_in?
end


test "should get save auth_hash to session " do
@user.activate
sign_in @user
Expand Down

0 comments on commit 868a9b7

Please sign in to comment.