debian-mirror-gitlab/spec/models/project_group_link_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.5 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ProjectGroupLink do
2016-06-02 11:05:42 +05:30
describe "Associations" do
2017-09-10 17:25:29 +05:30
it { is_expected.to belong_to(:group) }
it { is_expected.to belong_to(:project) }
2016-06-02 11:05:42 +05:30
end
describe "Validation" do
2017-08-17 22:00:37 +05:30
let(:parent_group) { create(:group) }
let(:group) { create(:group, parent: parent_group) }
let(:project) { create(:project, group: group) }
let!(:project_group_link) { create(:project_group_link, project: project) }
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_uniqueness_of(:group_id).scoped_to(:project_id).with_message(/already shared/) }
it { is_expected.to validate_presence_of(:group) }
it { is_expected.to validate_presence_of(:group_access) }
2017-08-17 22:00:37 +05:30
it "doesn't allow a project to be shared with the group it is in" do
project_group_link.group = group
expect(project_group_link).not_to be_valid
end
2019-10-12 21:52:04 +05:30
it "doesn't allow a project to be shared with an ancestor of the group it is in" do
2017-08-17 22:00:37 +05:30
project_group_link.group = parent_group
expect(project_group_link).not_to be_valid
end
2022-07-23 23:45:48 +05:30
it 'does not allow a project to be shared with `OWNER` access level' do
project_group_link.group_access = Gitlab::Access::OWNER
expect(project_group_link).not_to be_valid
end
2017-08-17 22:00:37 +05:30
end
2020-04-22 19:07:51 +05:30
describe 'scopes' do
describe '.non_guests' do
let!(:project_group_link_reporter) { create :project_group_link, :reporter }
let!(:project_group_link_maintainer) { create :project_group_link, :maintainer }
let!(:project_group_link_developer) { create :project_group_link }
let!(:project_group_link_guest) { create :project_group_link, :guest }
it 'returns all records which are greater than Guests access' do
expect(described_class.non_guests).to match_array([
2022-11-25 23:54:43 +05:30
project_group_link_reporter,
project_group_link_developer,
project_group_link_maintainer
2020-04-22 19:07:51 +05:30
])
end
end
end
2020-03-13 15:44:24 +05:30
describe 'search by group name' do
let_it_be(:project_group_link) { create(:project_group_link) }
let_it_be(:group) { project_group_link.group }
it { expect(described_class.search(group.name)).to eq([project_group_link]) }
it { expect(described_class.search('not-a-group-name')).to be_empty }
end
2016-06-02 11:05:42 +05:30
end