2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe MergeRequestTargetProjectFinder do
|
2018-03-17 18:26:18 +05:30
|
|
|
include ProjectForksHelper
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
subject(:finder) { described_class.new(current_user: user, source_project: forked_project) }
|
|
|
|
|
|
|
|
shared_examples 'finding related projects' do
|
2019-03-02 22:35:43 +05:30
|
|
|
it 'finds sibling projects and base project' do
|
2018-03-17 18:26:18 +05:30
|
|
|
other_fork
|
|
|
|
|
|
|
|
expect(finder.execute).to contain_exactly(base_project, other_fork, forked_project)
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'does not include projects that have merge requests turned off by default' do
|
2018-03-17 18:26:18 +05:30
|
|
|
other_fork.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
base_project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
|
|
|
|
expect(finder.execute).to contain_exactly(forked_project)
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'includes projects that have merge requests turned off by default with a more-permissive project feature' do
|
|
|
|
finder = described_class.new(current_user: user, source_project: forked_project, project_feature: :repository)
|
|
|
|
|
|
|
|
other_fork.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
base_project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
|
|
|
|
expect(finder.execute).to contain_exactly(base_project, other_fork, forked_project)
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it 'does not contain archived projects' do
|
|
|
|
base_project.update!(archived: true)
|
|
|
|
|
|
|
|
expect(finder.execute).to contain_exactly(other_fork, forked_project)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it 'does not include routes by default' do
|
|
|
|
row = finder.execute.first
|
|
|
|
|
|
|
|
expect(row.association(:route).loaded?).to be_falsey
|
|
|
|
expect(row.association(:namespace).loaded?).to be_falsey
|
|
|
|
expect(row.namespace.association(:route).loaded?).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes routes when requested' do
|
|
|
|
row = finder.execute(include_routes: true).first
|
|
|
|
|
|
|
|
expect(row.association(:route).loaded?).to be_truthy
|
|
|
|
expect(row.association(:namespace).loaded?).to be_truthy
|
|
|
|
expect(row.namespace.association(:route).loaded?).to be_truthy
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'public projects' do
|
|
|
|
let(:base_project) { create(:project, :public, path: 'base') }
|
|
|
|
let(:forked_project) { fork_project(base_project) }
|
|
|
|
let(:other_fork) { fork_project(base_project) }
|
|
|
|
|
|
|
|
it_behaves_like 'finding related projects'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'private projects' do
|
|
|
|
let(:base_project) { create(:project, :private, path: 'base') }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:forked_project) { fork_project(base_project, base_project.first_owner) }
|
|
|
|
let(:other_fork) { fork_project(base_project, base_project.first_owner) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'when the user is a member of all projects' do
|
|
|
|
before do
|
|
|
|
base_project.add_developer(user)
|
|
|
|
forked_project.add_developer(user)
|
|
|
|
other_fork.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'finding related projects'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only finds the projects the user is a member of' do
|
|
|
|
other_fork.add_developer(user)
|
|
|
|
base_project.add_developer(user)
|
|
|
|
|
|
|
|
expect(finder.execute).to contain_exactly(other_fork, base_project)
|
|
|
|
end
|
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
context 'searching' do
|
|
|
|
let(:base_project) { create(:project, :private, path: 'base') }
|
|
|
|
let(:forked_project) { fork_project(base_project, base_project.first_owner) }
|
|
|
|
let(:other_fork) { fork_project(base_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
base_project.add_developer(user)
|
|
|
|
forked_project.add_developer(user)
|
|
|
|
other_fork.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all projects with empty search' do
|
|
|
|
expect(finder.execute(search: '')).to match_array([base_project, forked_project, other_fork])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns forked project with search string' do
|
|
|
|
expect(finder.execute(search: forked_project.full_path)).to match_array([forked_project])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no projects with search for project that does no exist' do
|
|
|
|
expect(finder.execute(search: 'root')).to match_array([])
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|