2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-11 11:47:05 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectGroupLink do
|
|
|
|
describe "Associations" do
|
2017-06-29 12:03:17 -04:00
|
|
|
it { is_expected.to belong_to(:group) }
|
|
|
|
it { is_expected.to belong_to(:project) }
|
2016-03-11 11:47:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Validation" do
|
2017-02-27 17:38:45 -05:00
|
|
|
let(:parent_group) { create(:group) }
|
|
|
|
let(:group) { create(:group, parent: parent_group) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, group: group) }
|
2017-02-27 17:38:45 -05:00
|
|
|
let!(:project_group_link) { create(:project_group_link, project: project) }
|
2016-03-11 11:47:05 -05:00
|
|
|
|
2017-06-29 12:03:17 -04:00
|
|
|
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-02-27 17:38:45 -05:00
|
|
|
|
|
|
|
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-07-24 05:20:54 -04:00
|
|
|
it "doesn't allow a project to be shared with an ancestor of the group it is in" do
|
2017-02-27 17:38:45 -05:00
|
|
|
project_group_link.group = parent_group
|
|
|
|
|
|
|
|
expect(project_group_link).not_to be_valid
|
|
|
|
end
|
2016-03-11 11:47:05 -05:00
|
|
|
end
|
2016-10-11 08:25:17 -04:00
|
|
|
|
2020-04-09 14:09:34 -04:00
|
|
|
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([
|
|
|
|
project_group_link_reporter,
|
|
|
|
project_group_link_developer,
|
|
|
|
project_group_link_maintainer
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-17 06:30:25 -05:00
|
|
|
describe "destroying a record", :delete do
|
2016-10-11 08:25:17 -04:00
|
|
|
it "refreshes group users' authorized projects" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :private)
|
2016-10-11 08:25:17 -04:00
|
|
|
group = create(:group)
|
|
|
|
reporter = create(:user)
|
|
|
|
group_users = group.users
|
|
|
|
|
|
|
|
group.add_reporter(reporter)
|
|
|
|
project.project_group_links.create(group: group)
|
|
|
|
group_users.each { |user| expect(user.authorized_projects).to include(project) }
|
|
|
|
|
2018-08-16 08:46:40 -04:00
|
|
|
project.project_group_links.destroy_all # rubocop: disable DestroyAll
|
2016-10-11 08:25:17 -04:00
|
|
|
group_users.each { |user| expect(user.authorized_projects).not_to include(project) }
|
|
|
|
end
|
|
|
|
end
|
2020-01-31 07:08:33 -05:00
|
|
|
|
|
|
|
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-03-11 11:47:05 -05:00
|
|
|
end
|