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

94 lines
2.6 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe GroupMember do
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],
described_class::MASTER
)
expect(group.users).to include(users.first, users.second)
end
end
describe 'notifications' do
2015-04-26 12:48:37 +05:30
describe "#after_create" do
2016-09-13 17:45:13 +05:30
it "sends email to user" do
2015-04-26 12:48:37 +05:30
membership = build(:group_member)
2015-09-11 14:41:01 +05:30
2017-09-10 17:25:29 +05:30
allow(membership).to receive(:notification_service)
.and_return(double('NotificationService').as_null_object)
2015-04-26 12:48:37 +05:30
expect(membership).to receive(:notification_service)
2015-09-11 14:41:01 +05:30
2015-04-26 12:48:37 +05:30
membership.save
end
end
describe "#after_update" do
before do
@group_member = create :group_member
2017-09-10 17:25:29 +05:30
allow(@group_member).to receive(:notification_service)
.and_return(double('NotificationService').as_null_object)
2015-04-26 12:48:37 +05:30
end
2016-09-13 17:45:13 +05:30
it "sends email to user" do
2015-04-26 12:48:37 +05:30
expect(@group_member).to receive(:notification_service)
@group_member.update_attribute(:access_level, GroupMember::MASTER)
end
it "does not send an email when the access level has not changed" do
expect(@group_member).not_to receive(:notification_service)
@group_member.update_attribute(:access_level, GroupMember::OWNER)
end
end
describe '#after_accept_request' do
it 'calls NotificationService.accept_group_access_request' do
2017-08-17 22:00:37 +05:30
member = create(:group_member, user: build(:user), requested_at: Time.now)
expect_any_instance_of(NotificationService).to receive(:new_group_member)
member.__send__(:after_accept_request)
end
end
describe '#real_source_type' do
subject { create(:group_member).real_source_type }
it { is_expected.to eq 'Group' }
end
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
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
2015-04-26 12:48:37 +05:30
end