debian-mirror-gitlab/spec/models/members/group_member_spec.rb

149 lines
4.2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe GroupMember do
2019-12-04 20:38:33 +05:30
context 'scopes' do
2020-06-23 00:09:42 +05:30
shared_examples '.count_users_by_group_id' do
2019-12-04 20:38:33 +05:30
it 'counts users by group ID' do
user_1 = create(:user)
user_2 = create(:user)
group_1 = create(:group)
group_2 = create(:group)
2019-07-07 11:18:12 +05:30
2019-12-04 20:38:33 +05:30
group_1.add_owner(user_1)
group_1.add_owner(user_2)
group_2.add_owner(user_1)
2019-07-07 11:18:12 +05:30
2019-12-04 20:38:33 +05:30
expect(described_class.count_users_by_group_id).to eq(group_1.id => 2,
group_2.id => 1)
end
end
2020-06-23 00:09:42 +05:30
describe '.count_users_by_group_id with optimized_count_users_by_group_id feature flag on' do
before do
stub_feature_flags(optimized_count_users_by_group_id: true)
end
it_behaves_like '.count_users_by_group_id'
it 'does not JOIN users' do
scope = described_class.all
expect(scope).not_to receive(:joins).with(:user)
scope.count_users_by_group_id
end
end
describe '.count_users_by_group_id with optimized_count_users_by_group_id feature flag off' do
before do
stub_feature_flags(optimized_count_users_by_group_id: false)
end
it_behaves_like '.count_users_by_group_id'
it 'does JOIN users' do
scope = described_class.all
expect(scope).to receive(:joins).with(:user).and_call_original
scope.count_users_by_group_id
end
end
2019-12-04 20:38:33 +05:30
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
2019-07-07 11:18:12 +05:30
end
end
2016-11-03 12:29:30 +05:30
describe '.access_level_roles' do
it 'returns Gitlab::Access.options_with_owner' do
expect(described_class.access_level_roles).to eq(Gitlab::Access.options_with_owner)
end
end
describe '.access_levels' do
it 'returns Gitlab::Access.options_with_owner' do
expect(described_class.access_levels).to eq(Gitlab::Access.sym_options_with_owner)
end
end
2017-08-17 22:00:37 +05:30
describe '.add_users' do
2016-11-03 12:29:30 +05:30
it 'adds the given users to the given group' do
group = create(:group)
users = create_list(:user, 2)
2017-08-17 22:00:37 +05:30
described_class.add_users(
2016-11-03 12:29:30 +05:30
group,
[users.first.id, users.second],
2018-11-18 11:00:15 +05:30
described_class::MAINTAINER
2016-11-03 12:29:30 +05:30
)
expect(group.users).to include(users.first, users.second)
end
end
2018-10-15 14:42:47 +05:30
it_behaves_like 'members notifications', :group
2015-09-11 14:41:01 +05:30
2018-10-15 14:42:47 +05:30
describe '#real_source_type' do
subject { create(:group_member).real_source_type }
2015-09-11 14:41:01 +05:30
2018-10-15 14:42:47 +05:30
it { is_expected.to eq 'Group' }
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
describe '#update_two_factor_requirement' do
it 'is called after creation and deletion' do
2020-03-07 23:17:34 +05:30
user = build :user
group_member = build :group_member, user: user
2017-08-17 22:00:37 +05:30
expect(user).to receive(:update_two_factor_requirement)
group_member.save
expect(user).to receive(:update_two_factor_requirement)
group_member.destroy
end
end
2019-02-15 15:39:39 +05:30
2020-03-07 23:17:34 +05:30
describe '#after_accept_invite' do
it 'calls #update_two_factor_requirement' do
email = 'foo@email.com'
user = build(:user, email: email)
group = create(:group, require_two_factor_authentication: true)
group_member = create(:group_member, group: group, invite_token: '1234', invite_email: email)
expect(user).to receive(:require_two_factor_authentication_from_group).and_call_original
group_member.accept_invite!(user)
expect(user.require_two_factor_authentication_from_group).to be_truthy
end
end
2019-10-12 21:52:04 +05:30
context 'access levels' do
2019-02-15 15:39:39 +05:30
context 'with parent group' do
it_behaves_like 'inherited access level as a member of entity' do
let(:entity) { create(:group, parent: parent_entity) }
end
end
context 'with parent group and a sub subgroup' do
it_behaves_like 'inherited access level as a member of entity' do
let(:subgroup) { create(:group, parent: parent_entity) }
let(:entity) { create(:group, parent: subgroup) }
end
context 'when only the subgroup has the member' do
it_behaves_like 'inherited access level as a member of entity' do
let(:parent_entity) { create(:group, parent: create(:group)) }
let(:entity) { create(:group, parent: parent_entity) }
end
end
end
end
2015-04-26 12:48:37 +05:30
end