Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Session Controller tests for twitter #2962

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions test/functional/user_sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,60 @@ class UserSessionsControllerTest < ActionController::TestCase
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
end

test 'sign up and login via provider basic flow for twitter' do
assert_not_nil OmniAuth.config.mock_auth[:twitter1]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter1]
assert_not_nil request.env['omniauth.auth']
#Sign Up for a new user
post :create
assert_equal "You have successfully signed in. Please change your password via a link sent to you via a mail", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
#auth hash is present so login via a provider
post :create
assert_equal "Signed in!", flash[:notice]
end

test 'sign up and login via provider alternative flow for twitter' do
assert_not_nil OmniAuth.config.mock_auth[:twitter2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
assert_not_nil request.env['omniauth.auth']
#Sign Up for an existing user as email exists in the db
post :create
assert_equal "Successfully linked to your account!", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
#auth hash is present so login via a provider
post :create
assert_equal "Signed in!", flash[:notice]
end

test 'login user with an email and then contwitter provider' do
post :create,
params: {
user_session: {
username: users(:jeff).email,
password: 'secretive'
}
}
assert_redirected_to '/dashboard'
assert_not_nil OmniAuth.config.mock_auth[:twitter2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
assert_not_nil request.env['omniauth.auth']
#Link a twitter account to an existing user
post :create
assert_equal "Successfully linked to your account!", flash[:notice]
#Link same twitter account to an existing user again
post :create
assert_equal "Already linked to your account!", flash[:notice]
#Log Out
post :destroy
assert_equal "Successfully logged out.", flash[:notice]
end
end