debian-mirror-gitlab/spec/models/members/member_role_spec.rb
2023-03-05 14:24:40 +05:30

60 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MemberRole do
describe 'associations' do
it { is_expected.to belong_to(:namespace) }
it { is_expected.to have_many(:members) }
end
describe 'validation' do
subject(:member_role) { build(:member_role) }
it { is_expected.to validate_presence_of(:namespace) }
it { is_expected.to validate_presence_of(:base_access_level) }
context 'when for namespace' do
let_it_be(:root_group) { create(:group) }
context 'when namespace is a subgroup' do
it 'is invalid' do
subgroup = create(:group, parent: root_group)
member_role.namespace = subgroup
expect(member_role).to be_invalid
expect(member_role.errors[:namespace]).to include(
s_("MemberRole|must be top-level namespace")
)
end
end
context 'when namespace is a root group' do
it 'is valid' do
member_role.namespace = root_group
expect(member_role).to be_valid
end
end
context 'when namespace is not present' do
it 'is invalid with a different error message' do
member_role.namespace = nil
expect(member_role).to be_invalid
expect(member_role.errors[:namespace]).to include(_("can't be blank"))
end
end
context 'when namespace is outside hierarchy of member' do
it 'creates a validation error' do
member_role.save!
member_role.namespace = create(:group)
expect(member_role).not_to be_valid
expect(member_role.errors[:namespace]).to include(s_("MemberRole|can't be changed"))
end
end
end
end
end