2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe ProjectMember do
|
2016-06-16 23:09:34 +05:30
|
|
|
describe 'associations' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to belong_to(:project).with_foreign_key(:source_id) }
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to allow_value('Project').for(:source_type) }
|
|
|
|
it { is_expected.not_to allow_value('project').for(:source_type) }
|
2016-09-13 17:45:13 +05:30
|
|
|
it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'modules' do
|
|
|
|
it { is_expected.to include_module(Gitlab::ShellAdapter) }
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe '.access_level_roles' do
|
|
|
|
it 'returns Gitlab::Access.options' do
|
|
|
|
expect(described_class.access_level_roles).to eq(Gitlab::Access.options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.add_user' do
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'adds the user as a member' do
|
|
|
|
user = create(:user)
|
|
|
|
project = create(:project)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(project.users).not_to include(user)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
described_class.add_user(project, user, :maintainer, current_user: project.owner)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(project.users.reload).to include(user)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
describe '#real_source_type' do
|
|
|
|
subject { create(:project_member).real_source_type }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'Project' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:owner) { create(:project_member, access_level: ProjectMember::MAINTAINER) }
|
2016-06-16 23:09:34 +05:30
|
|
|
let(:project) { owner.project }
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:maintainer) { create(:project_member, project: project) }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "creates an expired event when left due to expiry" do
|
|
|
|
expired = create(:project_member, project: project, expires_at: Time.now - 6.days)
|
|
|
|
expired.destroy
|
|
|
|
expect(Event.recent.first.action).to eq(Event::EXPIRED)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a left event when left due to leave" do
|
2018-11-18 11:00:15 +05:30
|
|
|
maintainer.destroy
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Event.recent.first.action).to eq(Event::LEFT)
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe '.import_team' do
|
2015-04-26 12:48:37 +05:30
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
@project_1 = create(:project)
|
|
|
|
@project_2 = create(:project)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@project_1.add_developer(@user_1)
|
|
|
|
@project_2.add_reporter(@user_2)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
@status = @project_2.team.import(@project_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@status).to be_truthy }
|
|
|
|
|
|
|
|
describe 'project 2 should get user 1 as developer. user_2 should not be changed' do
|
|
|
|
it { expect(@project_2.users).to include(@user_1) }
|
|
|
|
it { expect(@project_2.users).to include(@user_2) }
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
it { expect(Ability.allowed?(@user_1, :create_project, @project_2)).to be_truthy }
|
|
|
|
it { expect(Ability.allowed?(@user_2, :read_project, @project_2)).to be_truthy }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'project 1 should not be changed' do
|
|
|
|
it { expect(@project_1.users).to include(@user_1) }
|
|
|
|
it { expect(@project_1.users).not_to include(@user_2) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe '.add_users_to_projects' do
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'adds the given users to the given projects' do
|
2017-09-10 17:25:29 +05:30
|
|
|
projects = create_list(:project, 2)
|
2016-11-03 12:29:30 +05:30
|
|
|
users = create_list(:user, 2)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
described_class.add_users_to_projects(
|
2017-08-17 22:00:37 +05:30
|
|
|
[projects.first.id, projects.second.id],
|
2016-11-03 12:29:30 +05:30
|
|
|
[users.first.id, users.second],
|
2018-11-18 11:00:15 +05:30
|
|
|
described_class::MAINTAINER)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(projects.first.users).to include(users.first)
|
|
|
|
expect(projects.first.users).to include(users.second)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(projects.second.users).to include(users.first)
|
|
|
|
expect(projects.second.users).to include(users.second)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '.truncate_teams' do
|
2015-04-26 12:48:37 +05:30
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
@project_1 = create(:project)
|
|
|
|
@project_2 = create(:project)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@project_1.add_developer(@user_1)
|
|
|
|
@project_2.add_reporter(@user_2)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
described_class.truncate_teams([@project_1.id, @project_2.id])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@project_1.users).to be_empty }
|
|
|
|
it { expect(@project_2.users).to be_empty }
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it_behaves_like 'members notifications', :project
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|