From 892612fe9b743ae27ade6e9d69f3174cf312d64c Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 20 Jan 2016 18:15:14 +0100 Subject: [PATCH] Adds two new scenarios to auth specs --- spec/features/users_auth_spec.rb | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/spec/features/users_auth_spec.rb b/spec/features/users_auth_spec.rb index ea677eb3a..831a2b0a5 100644 --- a/spec/features/users_auth_spec.rb +++ b/spec/features/users_auth_spec.rb @@ -132,6 +132,63 @@ feature 'Users' do expect_to_be_signed_in end + + scenario 'Try to register with the username of an already existing user' do + create(:user, username: 'manuela', email: 'manuela@madrid.es', password: 'judgementday') + OmniAuth.config.add_mock(:twitter, twitter_hash_with_email) + + visit '/' + click_link 'Register' + click_link 'Sign up with Twitter' + + expect(current_path).to eq(finish_signup_path) + + fill_in 'user_username', with: 'manuela2' + click_button 'Register' + + expect_to_be_signed_in + + click_link 'My account' + expect(page).to have_field('account_username', with: 'manuela2') + + visit edit_user_registration_path + expect(page).to have_field('user_email', with: 'manuelacarmena@example.com') + end + + scenario 'Try to register with the email of an already existing user' do + create(:user, username: 'peter', email: 'manuela@example.com') + OmniAuth.config.add_mock(:twitter, twitter_hash) + + visit '/' + click_link 'Register' + click_link 'Sign up with Twitter' + + expect(current_path).to eq(finish_signup_path) + + fill_in 'user_email', with: 'manuela@example.com' + click_button 'Register' + + expect(current_path).to eq(do_finish_signup_path) + + fill_in 'user_email', with: 'somethingelse@example.com' + click_button 'Register' + + expect(page).to have_content "You must confirm your account to continue" + + confirm_email + expect(page).to have_content "Your account has been confirmed" + + visit '/' + click_link 'Sign in' + click_link 'Sign in with Twitter' + expect_to_be_signed_in + + click_link 'My account' + expect(page).to have_field('account_username', with: 'manuela') + + visit edit_user_registration_path + expect(page).to have_field('user_email', with: 'somethingelse@example.com') + end end end