debian-mirror-gitlab/spec/services/projects/move_project_members_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.2 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Projects::MoveProjectMembersService do
2018-05-09 12:01:36 +05:30
let!(:user) { create(:user) }
let(:project_with_users) { create(:project, namespace: user.namespace) }
let(:target_project) { create(:project, namespace: user.namespace) }
2018-11-18 11:00:15 +05:30
let(:maintainer_user) { create(:user) }
2018-05-09 12:01:36 +05:30
let(:reporter_user) { create(:user) }
let(:developer_user) { create(:user) }
subject { described_class.new(target_project, user) }
describe '#execute' do
before do
2018-11-18 11:00:15 +05:30
project_with_users.add_maintainer(maintainer_user)
2018-05-09 12:01:36 +05:30
project_with_users.add_developer(developer_user)
project_with_users.add_reporter(reporter_user)
end
it 'moves the members from one project to another' do
expect(project_with_users.project_members.count).to eq 4
expect(target_project.project_members.count).to eq 1
subject.execute(project_with_users)
expect(project_with_users.project_members.count).to eq 0
expect(target_project.project_members.count).to eq 4
end
it 'does not move existent members to the current project' do
2018-11-18 11:00:15 +05:30
target_project.add_maintainer(developer_user)
2018-05-09 12:01:36 +05:30
target_project.add_developer(reporter_user)
expect(project_with_users.project_members.count).to eq 4
expect(target_project.project_members.count).to eq 3
subject.execute(project_with_users)
expect(project_with_users.project_members.count).to eq 0
expect(target_project.project_members.count).to eq 4
end
it 'rollbacks changes if transaction fails' do
allow(subject).to receive(:success).and_raise(StandardError)
expect { subject.execute(project_with_users) }.to raise_error(StandardError)
expect(project_with_users.project_members.count).to eq 4
expect(target_project.project_members.count).to eq 1
end
context 'when remove_remaining_elements is false' do
let(:options) { { remove_remaining_elements: false } }
it 'does not remove remaining project members' do
2018-11-18 11:00:15 +05:30
target_project.add_maintainer(developer_user)
2018-05-09 12:01:36 +05:30
target_project.add_developer(reporter_user)
2021-02-22 17:27:13 +05:30
subject.execute(project_with_users, **options)
2018-05-09 12:01:36 +05:30
expect(project_with_users.project_members.count).not_to eq 0
end
end
end
end