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

51 lines
1.7 KiB
Ruby
Raw Normal View History

2019-05-18 00:54:41 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
describe ProjectGroupLink do
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
2017-09-10 17:25:29 +05:30
it "doesn't allow a project to be shared with an ancestor of the group it is in", :nested_groups do
2017-08-17 22:00:37 +05:30
project_group_link.group = parent_group
expect(project_group_link).not_to be_valid
end
end
2018-03-17 18:26:18 +05:30
describe "destroying a record", :delete do
2017-08-17 22:00:37 +05:30
it "refreshes group users' authorized projects" do
2017-09-10 17:25:29 +05:30
project = create(:project, :private)
2017-08-17 22:00:37 +05:30
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-11-20 20:47:30 +05:30
project.project_group_links.destroy_all # rubocop: disable DestroyAll
2017-08-17 22:00:37 +05:30
group_users.each { |user| expect(user.authorized_projects).not_to include(project) }
end
2016-06-02 11:05:42 +05:30
end
end