@@ -872,15 +872,33 @@ class OmniauthCallbacksControllerTest < ActionController::TestCase
872
872
end
873
873
874
874
test "connect_provider: Refuses to link credential if there is an account with matching credential that has activity" do
875
+ user = create :user , :multi_auth_migrated
876
+
875
877
# Given there exists another user
876
878
# having credential X
877
879
# and having activity
880
+ other_user = create :user , :multi_auth_migrated
881
+ credential = create :google_authentication_option , user : other_user
882
+ create :user_level , user : other_user , best_result : ActivityConstants ::MINIMUM_PASS_RESULT
883
+ assert other_user . has_activity?
878
884
879
885
# When I attempt to add credential X
886
+ link_credential user ,
887
+ type : credential . credential_type ,
888
+ id : credential . authentication_id
889
+
890
+ # Then the other user should not be destroyed
891
+ other_user . reload
892
+ refute other_user . deleted?
880
893
881
- # Then I should fail to add credential X
882
- # And the other user should not be destroyed
883
- # And I should receive a helpful error message about the credential already being in use.
894
+ # And I should fail to add credential X
895
+ user . reload
896
+ assert_empty user . authentication_options
897
+
898
+ # And receive a helpful error message about the credential already being in use.
899
+ assert_redirected_to 'http://test.host/users/edit'
900
+ expected_error = I18n . t ( 'auth.already_in_use' , provider : I18n . t ( "auth.google_oauth2" ) )
901
+ assert_equal expected_error , flash . alert
884
902
end
885
903
886
904
private
0 commit comments