2015-04-26 12:48:37 +05:30
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: members
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# access_level :integer not null
|
|
|
|
# source_id :integer not null
|
|
|
|
# source_type :string(255) not null
|
2015-09-11 14:41:01 +05:30
|
|
|
# user_id :integer
|
2015-04-26 12:48:37 +05:30
|
|
|
# notification_level :integer not null
|
|
|
|
# type :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2015-09-11 14:41:01 +05:30
|
|
|
# created_by_id :integer
|
|
|
|
# invite_email :string(255)
|
|
|
|
# invite_token :string(255)
|
|
|
|
# invite_accepted_at :datetime
|
2015-04-26 12:48:37 +05:30
|
|
|
#
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe ProjectMember, models: true do
|
2016-06-16 23:09:34 +05:30
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project).class_name('Project').with_foreign_key(:source_id) }
|
|
|
|
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
|
|
|
|
|
|
|
|
describe '#real_source_type' do
|
|
|
|
subject { create(:project_member).real_source_type }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'Project' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:owner) { create(:project_member, access_level: ProjectMember::MASTER) }
|
2016-06-16 23:09:34 +05:30
|
|
|
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-09-13 17:45:13 +05:30
|
|
|
it "destroys itself and delete associated todos" do
|
2016-06-16 23:09:34 +05:30
|
|
|
expect(owner.user.todos.size).to eq(2)
|
|
|
|
expect(master.user.todos.size).to eq(3)
|
|
|
|
expect(Todo.count).to eq(5)
|
|
|
|
|
|
|
|
master_todo_ids = master_todos.map(&:id)
|
|
|
|
master.destroy
|
|
|
|
|
|
|
|
expect(owner.user.todos.size).to eq(2)
|
|
|
|
expect(Todo.count).to eq(2)
|
|
|
|
master_todo_ids.each do |id|
|
|
|
|
expect(Todo.exists?(id)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
describe :import_team do
|
|
|
|
before do
|
|
|
|
@abilities = Six.new
|
|
|
|
@abilities << Ability
|
|
|
|
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
|
|
|
@project_1.team << [ @user_1, :developer ]
|
|
|
|
@project_2.team << [ @user_2, :reporter ]
|
|
|
|
|
|
|
|
@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) }
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
it { expect(@abilities.allowed?(@user_1, :create_project, @project_2)).to be_truthy }
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@abilities.allowed?(@user_2, :read_project, @project_2)).to be_truthy }
|
|
|
|
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
|
2015-04-26 12:48:37 +05:30
|
|
|
before do
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
ProjectMember.add_users_to_projects(
|
2015-04-26 12:48:37 +05:30
|
|
|
[@project_1.id, @project_2.id],
|
|
|
|
[@user_1.id, @user_2.id],
|
|
|
|
ProjectMember::MASTER
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@project_1.users).to include(@user_1) }
|
|
|
|
it { expect(@project_1.users).to include(@user_2) }
|
|
|
|
|
|
|
|
it { expect(@project_2.users).to include(@user_1) }
|
|
|
|
it { expect(@project_2.users).to include(@user_2) }
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '.truncate_teams' do
|
2015-04-26 12:48:37 +05:30
|
|
|
before do
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
|
|
|
@project_1.team << [ @user_1, :developer]
|
|
|
|
@project_2.team << [ @user_2, :reporter]
|
|
|
|
|
|
|
|
ProjectMember.truncate_teams([@project_1.id, @project_2.id])
|
|
|
|
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
|
|
|
|
|
|
|
describe 'notifications' do
|
|
|
|
describe '#after_accept_request' do
|
|
|
|
it 'calls NotificationService.new_project_member' do
|
|
|
|
member = create(:project_member, user: build_stubbed(:user), requested_at: Time.now)
|
|
|
|
|
|
|
|
expect_any_instance_of(NotificationService).to receive(:new_project_member)
|
|
|
|
|
|
|
|
member.__send__(:after_accept_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|