From 75b2ff8f43d52c76d4d4eaac37618295b5046cc6 Mon Sep 17 00:00:00 2001
From: Izaak Alpert <ialpert@blackberry.com>
Date: Mon, 16 Sep 2013 00:40:21 -0400
Subject: [PATCH] Added ldap tests

Change-Id: Ifd77615b3b92d7d8bca92b8875aa8204356cfd85
---
 .../ldap/ldap_user_auth_spec.rb}              | 51 ++-----------------
 1 file changed, 5 insertions(+), 46 deletions(-)
 rename spec/lib/{auth_oauth_spec.rb => gitlab/ldap/ldap_user_auth_spec.rb} (53%)

diff --git a/spec/lib/auth_oauth_spec.rb b/spec/lib/gitlab/ldap/ldap_user_auth_spec.rb
similarity index 53%
rename from spec/lib/auth_oauth_spec.rb
rename to spec/lib/gitlab/ldap/ldap_user_auth_spec.rb
index c9deb590f67..b1c583c0476 100644
--- a/spec/lib/auth_oauth_spec.rb
+++ b/spec/lib/gitlab/ldap/ldap_user_auth_spec.rb
@@ -1,7 +1,7 @@
 require 'spec_helper'
 
-describe Gitlab::Auth do
-  let(:gl_auth) { Gitlab::Auth.new }
+describe Gitlab::LDAP do
+  let(:gl_auth) { Gitlab::LDAP::User }
 
   before do
     Gitlab.config.stub(omniauth: {})
@@ -22,17 +22,12 @@ describe Gitlab::Auth do
       )
     end
 
-    it "should find by uid & provider" do
-      User.should_receive :find_by_extern_uid_and_provider
-      gl_auth.find_for_ldap_auth(@auth)
-    end
-
     it "should update credentials by email if missing uid" do
       user = double('User')
       User.stub find_by_extern_uid_and_provider: nil
       User.stub find_by_email: user
       user.should_receive :update_attributes
-      gl_auth.find_for_ldap_auth(@auth)
+      gl_auth.find_or_create(@auth)
     end
 
     it "should update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is true" do
@@ -43,7 +38,7 @@ describe Gitlab::Auth do
       User.stub find_by_email: nil
       User.stub find_by_username: user
       user.should_receive :update_attributes
-      gl_auth.find_for_ldap_auth(@auth)
+      gl_auth.find_or_create(@auth)
       Gitlab.config.ldap['allow_username_or_email_login'] = value
     end
 
@@ -55,44 +50,8 @@ describe Gitlab::Auth do
       User.stub find_by_email: nil
       User.stub find_by_username: user
       user.should_not_receive :update_attributes
-      gl_auth.find_for_ldap_auth(@auth)
+      gl_auth.find_or_create(@auth)
       Gitlab.config.ldap['allow_username_or_email_login'] = value
     end
-
-    it "should create from auth if user does not exist"do
-      User.stub find_by_extern_uid_and_provider: nil
-      User.stub find_by_email: nil
-      gl_auth.should_receive :create_from_omniauth
-      gl_auth.find_for_ldap_auth(@auth)
-    end
-  end
-
-  describe :find_or_new_for_omniauth do
-    before do
-      @auth = mock(
-        info: @info,
-        provider: 'twitter',
-        uid: '12djsak321',
-      )
-    end
-
-    it "should find user"do
-      User.should_receive :find_by_provider_and_extern_uid
-      gl_auth.should_not_receive :create_from_omniauth
-      gl_auth.find_or_new_for_omniauth(@auth)
-    end
-
-    it "should not create user"do
-      User.stub find_by_provider_and_extern_uid: nil
-      gl_auth.should_not_receive :create_from_omniauth
-      gl_auth.find_or_new_for_omniauth(@auth)
-    end
-
-    it "should create user if single_sing_on"do
-      Gitlab.config.omniauth['allow_single_sign_on'] = true
-      User.stub find_by_provider_and_extern_uid: nil
-      gl_auth.should_receive :create_from_omniauth
-      gl_auth.find_or_new_for_omniauth(@auth)
-    end
   end
 end
-- 
GitLab