Commit f53112de authored by Ash McKenzie's avatar Ash McKenzie Committed by Ash McKenzie

New GroupMember.of_ldap_type scope

parent d00d60a6
...@@ -13,8 +13,8 @@ class GroupMember < Member ...@@ -13,8 +13,8 @@ class GroupMember < Member
default_scope { where(source_type: SOURCE_TYPE) } default_scope { where(source_type: SOURCE_TYPE) }
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) } scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
scope :count_users_by_group_id, -> { joins(:user).group(:source_id).count } scope :count_users_by_group_id, -> { joins(:user).group(:source_id).count }
scope :of_ldap_type, -> { where(ldap: true) }
after_create :update_two_factor_requirement, unless: :invite? after_create :update_two_factor_requirement, unless: :invite?
after_destroy :update_two_factor_requirement, unless: :invite? after_destroy :update_two_factor_requirement, unless: :invite?
......
...@@ -16,5 +16,9 @@ FactoryBot.define do ...@@ -16,5 +16,9 @@ FactoryBot.define do
invite_token 'xxx' invite_token 'xxx'
invite_email 'email@email.com' invite_email 'email@email.com'
end end
trait(:ldap) do
ldap true
end
end end
end end
...@@ -3,19 +3,29 @@ ...@@ -3,19 +3,29 @@
require 'spec_helper' require 'spec_helper'
describe GroupMember do describe GroupMember do
describe '.count_users_by_group_id' do context 'scopes' do
it 'counts users by group ID' do describe '.count_users_by_group_id' do
user_1 = create(:user) it 'counts users by group ID' do
user_2 = create(:user) user_1 = create(:user)
group_1 = create(:group) user_2 = create(:user)
group_2 = create(:group) group_1 = create(:group)
group_2 = create(:group)
group_1.add_owner(user_1)
group_1.add_owner(user_2) group_1.add_owner(user_1)
group_2.add_owner(user_1) group_1.add_owner(user_2)
group_2.add_owner(user_1)
expect(described_class.count_users_by_group_id).to eq(group_1.id => 2,
group_2.id => 1) expect(described_class.count_users_by_group_id).to eq(group_1.id => 2,
group_2.id => 1)
end
end
describe '.of_ldap_type' do
it 'returns ldap type users' do
group_member = create(:group_member, :ldap)
expect(described_class.of_ldap_type).to eq([group_member])
end
end 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