Commit 2424df1f authored by James Lopez's avatar James Lopez

add more specs, fixed some errors

parent 25059dd3
......@@ -230,12 +230,20 @@ class Group < Namespace
ldap_group_links.first.try(:cn)
end
def ldap_filter
ldap_group_links.first.try(:filter)
end
def ldap_access
ldap_group_links.first.try(:group_access)
end
def ldap_cn_or_filter_present?
ldap_cn.present? || ldap_filter.present?
end
def ldap_synced?
Gitlab.config.ldap.enabled && ldap_cn.present?
Gitlab.config.ldap.enabled && ldap_cn_or_filter_present?
end
def post_create_hook
......
......@@ -8,7 +8,7 @@ class LdapGroupLink < ActiveRecord::Base
validates :cn, uniqueness: { scope: [:group_id, :provider] }, unless: :filter
validates :filter, :group_access, :group_id, presence: true, unless: :cn
validates :filter, uniqueness: { scope: [:group_id, :provider] }, unless: :cn
validates :filter, ldap_filter: true, if: :filter
validates :filter, ldap_filter: true, unless: :cn
validates :group_access, inclusion: { in: Gitlab::Access.all_values }
validates :provider, presence: true
......
......@@ -27,20 +27,34 @@ FactoryGirl.define do
end
end
factory :group_with_ldap_group_link do
factory :group_with_ldap do
transient do
cn 'group1'
group_access Gitlab::Access::GUEST
provider 'ldapmain'
end
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
cn: evaluator.cn,
group_access: evaluator.group_access,
provider: evaluator.provider
)
factory :group_with_ldap_group_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
cn: evaluator.cn,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end
factory :group_with_ldap_group_filter_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
filter: '(a=b)',
cn: nil,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment