2013-06-17 06:07:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe GroupMember do
|
2016-09-16 11:54:21 -04:00
|
|
|
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-04-21 10:07:42 -04:00
|
|
|
describe '.add_users' do
|
2016-09-16 11:54:21 -04:00
|
|
|
it 'adds the given users to the given group' do
|
|
|
|
group = create(:group)
|
|
|
|
users = create_list(:user, 2)
|
|
|
|
|
2017-04-21 10:07:42 -04:00
|
|
|
described_class.add_users(
|
2016-09-16 11:54:21 -04:00
|
|
|
group,
|
|
|
|
[users.first.id, users.second],
|
|
|
|
described_class::MASTER
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(group.users).to include(users.first, users.second)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-18 12:53:32 -04:00
|
|
|
describe 'notifications' do
|
2014-06-17 14:36:40 -04:00
|
|
|
describe "#after_create" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "sends email to user" do
|
2014-09-15 04:36:50 -04:00
|
|
|
membership = build(:group_member)
|
2015-05-21 17:49:06 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(membership).to receive(:notification_service)
|
|
|
|
.and_return(double('NotificationService').as_null_object)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(membership).to receive(:notification_service)
|
2015-05-21 17:49:06 -04:00
|
|
|
|
2014-06-17 14:36:40 -04:00
|
|
|
membership.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#after_update" do
|
|
|
|
before do
|
2015-03-13 11:16:51 -04:00
|
|
|
@group_member = create :group_member
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(@group_member).to receive(:notification_service)
|
|
|
|
.and_return(double('NotificationService').as_null_object)
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "sends email to user" do
|
2015-03-13 11:16:51 -04:00
|
|
|
expect(@group_member).to receive(:notification_service)
|
|
|
|
@group_member.update_attribute(:access_level, GroupMember::MASTER)
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not send an email when the access level has not changed" do
|
2015-03-13 11:16:51 -04:00
|
|
|
expect(@group_member).not_to receive(:notification_service)
|
|
|
|
@group_member.update_attribute(:access_level, GroupMember::OWNER)
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
|
|
|
end
|
2016-04-18 12:53:32 -04:00
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
describe '#after_accept_request' do
|
|
|
|
it 'calls NotificationService.accept_group_access_request' do
|
2017-01-24 16:09:58 -05:00
|
|
|
member = create(:group_member, user: build(:user), requested_at: Time.now)
|
2016-04-18 12:53:32 -04:00
|
|
|
|
|
|
|
expect_any_instance_of(NotificationService).to receive(:new_group_member)
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
member.__send__(:after_accept_request)
|
2016-04-18 12:53:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
describe '#real_source_type' do
|
|
|
|
subject { create(:group_member).real_source_type }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'Group' }
|
|
|
|
end
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
2017-01-24 16:09:58 -05:00
|
|
|
|
|
|
|
describe '#update_two_factor_requirement' do
|
|
|
|
let(:user) { build :user }
|
|
|
|
let(:group_member) { build :group_member, user: user }
|
|
|
|
|
|
|
|
it 'is called after creation and deletion' do
|
|
|
|
expect(user).to receive(:update_two_factor_requirement)
|
|
|
|
|
|
|
|
group_member.save
|
|
|
|
|
|
|
|
expect(user).to receive(:update_two_factor_requirement)
|
|
|
|
|
|
|
|
group_member.destroy
|
|
|
|
end
|
|
|
|
end
|
2013-06-17 06:07:16 -04:00
|
|
|
end
|