2011-10-08 17:36:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe ProjectMember, models: true do
|
2016-05-20 13:37:48 -04:00
|
|
|
describe 'associations' do
|
2016-10-18 17:20:36 -04:00
|
|
|
it { is_expected.to belong_to(:project).with_foreign_key(:source_id) }
|
2016-05-20 13:37:48 -04:00
|
|
|
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-06-23 11:14:31 -04:00
|
|
|
it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
|
2016-05-20 13:37:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'modules' do
|
|
|
|
it { is_expected.to include_module(Gitlab::ShellAdapter) }
|
|
|
|
end
|
|
|
|
|
2016-09-16 11:54:21 -04:00
|
|
|
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
|
|
|
|
context 'when called with the project owner' do
|
|
|
|
it 'adds the user as a member' do
|
|
|
|
project = create(:empty_project)
|
|
|
|
|
|
|
|
expect(project.users).not_to include(project.owner)
|
|
|
|
|
|
|
|
described_class.add_user(project, project.owner, :master, current_user: project.owner)
|
|
|
|
|
|
|
|
expect(project.users.reload).to include(project.owner)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
describe '#real_source_type' do
|
|
|
|
subject { create(:project_member).real_source_type }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'Project' }
|
|
|
|
end
|
|
|
|
|
2016-05-20 13:37:48 -04:00
|
|
|
describe "#destroy" do
|
2016-06-23 11:14:31 -04:00
|
|
|
let(:owner) { create(:project_member, access_level: ProjectMember::MASTER) }
|
2016-05-20 13:37:48 -04:00
|
|
|
let(:project) { owner.project }
|
|
|
|
let(:master) { create(:project_member, project: project) }
|
|
|
|
|
|
|
|
let(:owner_todos) { (0...2).map { create(:todo, user: owner.user, project: project) } }
|
|
|
|
let(:master_todos) { (0...3).map { create(:todo, user: master.user, project: project) } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
owner_todos
|
|
|
|
master_todos
|
|
|
|
end
|
|
|
|
|
2016-10-06 11:19:27 -04:00
|
|
|
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
|
2016-10-27 00:48:26 -04:00
|
|
|
expect(Event.recent.first.action).to eq(Event::EXPIRED)
|
2016-10-06 11:19:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a left event when left due to leave" do
|
|
|
|
master.destroy
|
2016-10-27 00:48:26 -04:00
|
|
|
expect(Event.recent.first.action).to eq(Event::LEFT)
|
2016-10-06 11:19:27 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "destroys itself and delete associated todos" do
|
2016-05-21 12:11:26 -04:00
|
|
|
expect(owner.user.todos.size).to eq(2)
|
|
|
|
expect(master.user.todos.size).to eq(3)
|
2016-05-20 13:37:48 -04:00
|
|
|
expect(Todo.count).to eq(5)
|
|
|
|
|
|
|
|
master_todo_ids = master_todos.map(&:id)
|
|
|
|
master.destroy
|
|
|
|
|
2016-05-21 12:11:26 -04:00
|
|
|
expect(owner.user.todos.size).to eq(2)
|
2016-05-20 13:37:48 -04:00
|
|
|
expect(Todo.count).to eq(2)
|
|
|
|
master_todo_ids.each do |id|
|
|
|
|
expect(Todo.exists?(id)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-16 11:54:21 -04:00
|
|
|
describe '.import_team' do
|
2012-10-24 07:52:17 -04:00
|
|
|
before do
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2013-01-04 01:43:25 -05:00
|
|
|
@project_1.team << [ @user_1, :developer ]
|
|
|
|
@project_2.team << [ @user_2, :reporter ]
|
2012-10-24 07:52:17 -04:00
|
|
|
|
2013-01-04 01:43:25 -05:00
|
|
|
@status = @project_2.team.import(@project_1)
|
2012-10-24 07:52:17 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@status).to be_truthy }
|
2012-10-24 07:52:17 -04:00
|
|
|
|
|
|
|
describe 'project 2 should get user 1 as developer. user_2 should not be changed' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@project_2.users).to include(@user_1) }
|
|
|
|
it { expect(@project_2.users).to include(@user_2) }
|
2012-10-24 07:52:17 -04:00
|
|
|
|
2016-08-08 14:55:13 -04:00
|
|
|
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 }
|
2012-10-24 07:52:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'project 1 should not be changed' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@project_1.users).to include(@user_1) }
|
|
|
|
it { expect(@project_1.users).not_to include(@user_2) }
|
2012-10-24 07:52:17 -04:00
|
|
|
end
|
|
|
|
end
|
2013-01-03 12:11:14 -05:00
|
|
|
|
2016-08-04 00:35:17 -04:00
|
|
|
describe '.add_users_to_projects' do
|
2016-09-16 11:54:21 -04:00
|
|
|
it 'adds the given users to the given projects' do
|
|
|
|
projects = create_list(:empty_project, 2)
|
|
|
|
users = create_list(:user, 2)
|
2013-01-03 12:11:14 -05:00
|
|
|
|
2016-09-16 11:54:21 -04:00
|
|
|
described_class.add_users_to_projects(
|
|
|
|
[projects.first.id, projects.second],
|
|
|
|
[users.first.id, users.second],
|
|
|
|
described_class::MASTER)
|
2013-01-03 12:11:14 -05:00
|
|
|
|
2016-09-16 11:54:21 -04:00
|
|
|
expect(projects.first.users).to include(users.first)
|
|
|
|
expect(projects.first.users).to include(users.second)
|
2013-01-03 12:11:14 -05:00
|
|
|
|
2016-09-16 11:54:21 -04:00
|
|
|
expect(projects.second.users).to include(users.first)
|
|
|
|
expect(projects.second.users).to include(users.second)
|
|
|
|
end
|
2013-01-03 12:11:14 -05:00
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '.truncate_teams' do
|
2013-01-03 12:11:14 -05:00
|
|
|
before do
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2013-01-04 01:43:25 -05:00
|
|
|
@project_1.team << [ @user_1, :developer]
|
|
|
|
@project_2.team << [ @user_2, :reporter]
|
2013-01-03 12:11:14 -05:00
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
ProjectMember.truncate_teams([@project_1.id, @project_2.id])
|
2013-01-03 12:11:14 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@project_1.users).to be_empty }
|
|
|
|
it { expect(@project_2.users).to be_empty }
|
2013-01-03 12:11:14 -05:00
|
|
|
end
|
2016-04-18 12:53:32 -04:00
|
|
|
|
|
|
|
describe 'notifications' do
|
2016-06-02 12:05:06 -04:00
|
|
|
describe '#after_accept_request' do
|
|
|
|
it 'calls NotificationService.new_project_member' do
|
|
|
|
member = create(:project_member, user: build_stubbed(:user), requested_at: Time.now)
|
2016-04-18 12:53:32 -04:00
|
|
|
|
|
|
|
expect_any_instance_of(NotificationService).to receive(:new_project_member)
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
member.__send__(:after_accept_request)
|
2016-04-18 12:53:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|