2016-08-05 09:29:20 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
describe Autocomplete::MoveToProjectFinder do
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:no_access_project) { create(:project) }
|
|
|
|
let(:guest_project) { create(:project) }
|
2019-07-22 07:44:20 -04:00
|
|
|
let(:reporter_project) { create(:project, name: 'name') }
|
|
|
|
let(:developer_project) { create(:project, name: 'name2') }
|
|
|
|
let(:maintainer_project) { create(:project, name: 'name3') }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'filter' do
|
|
|
|
it 'does not return projects under Gitlab::Access::REPORTER' do
|
2017-12-22 03:18:28 -05:00
|
|
|
guest_project.add_guest(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute).to be_empty
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2019-07-22 07:44:20 -04:00
|
|
|
it 'returns projects equal or above Gitlab::Access::REPORTER ordered by name' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
|
|
|
developer_project.add_developer(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
maintainer_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
2019-07-22 07:44:20 -04:00
|
|
|
expect(finder.execute.to_a).to eq([reporter_project, developer_project, maintainer_project])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include the source project' do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_reporter(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to be_empty
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return archived projects' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
2018-08-02 15:39:46 -04:00
|
|
|
::Projects::UpdateService.new(reporter_project, user, archived: true).execute
|
2017-08-02 15:55:11 -04:00
|
|
|
other_reporter_project = create(:project)
|
2017-12-22 03:18:28 -05:00
|
|
|
other_reporter_project.add_reporter(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to eq([other_reporter_project])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return projects for which issues are disabled' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
2018-07-02 06:43:06 -04:00
|
|
|
reporter_project.update(issues_enabled: false)
|
2017-08-02 15:55:11 -04:00
|
|
|
other_reporter_project = create(:project)
|
2017-12-22 03:18:28 -05:00
|
|
|
other_reporter_project.add_reporter(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to eq([other_reporter_project])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2019-07-22 07:44:20 -04:00
|
|
|
it 'returns a page of projects ordered by name' do
|
|
|
|
stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2019-07-22 07:44:20 -04:00
|
|
|
projects = create_list(:project, 3) do |project|
|
2018-07-30 11:45:49 -04:00
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
page = finder.execute.to_a
|
|
|
|
|
2019-07-22 07:44:20 -04:00
|
|
|
expected_projects = projects.sort_by(&:name).first(2)
|
|
|
|
expect(page.length).to eq(2)
|
|
|
|
expect(page).to eq(expected_projects)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2018-07-30 11:45:49 -04:00
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
context 'search' do
|
2016-08-05 09:29:20 -04:00
|
|
|
it 'returns projects matching a search query' do
|
2019-07-22 07:44:20 -04:00
|
|
|
foo_project = create(:project, name: 'foo')
|
2018-07-11 10:36:08 -04:00
|
|
|
foo_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
wadus_project = create(:project, name: 'wadus')
|
2018-07-11 10:36:08 -04:00
|
|
|
wadus_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
expect(described_class.new(user, project_id: project.id).execute.to_a)
|
2019-07-22 07:44:20 -04:00
|
|
|
.to eq([foo_project, wadus_project])
|
2018-07-30 11:45:49 -04:00
|
|
|
|
|
|
|
expect(described_class.new(user, project_id: project.id, search: 'wadus').execute.to_a)
|
|
|
|
.to eq([wadus_project])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|