debian-mirror-gitlab/spec/finders/autocomplete/move_to_project_finder_spec.rb

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

108 lines
3.6 KiB
Ruby
Raw Permalink Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Autocomplete::MoveToProjectFinder do
2020-04-22 19:07:51 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
let(:no_access_project) { create(:project) }
let(:guest_project) { create(:project) }
2019-10-12 21:52:04 +05:30
let(:reporter_project) { create(:project, name: 'name') }
let(:developer_project) { create(:project, name: 'name2') }
let(:maintainer_project) { create(:project, name: 'name3') }
2016-09-13 17:45:13 +05:30
describe '#execute' do
context 'filter' do
it 'does not return projects under Gitlab::Access::REPORTER' do
2018-03-17 18:26:18 +05:30
guest_project.add_guest(user)
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
finder = described_class.new(user, project_id: project.id)
expect(finder.execute).to be_empty
2016-09-13 17:45:13 +05:30
end
2020-10-24 23:57:45 +05:30
it 'returns projects equal or above Gitlab::Access::REPORTER' do
2018-03-17 18:26:18 +05:30
reporter_project.add_reporter(user)
developer_project.add_developer(user)
2018-11-18 11:00:15 +05:30
maintainer_project.add_maintainer(user)
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
finder = described_class.new(user, project_id: project.id)
2020-10-24 23:57:45 +05:30
expect(finder.execute.to_a).to contain_exactly(reporter_project, developer_project, maintainer_project)
2016-09-13 17:45:13 +05:30
end
it 'does not include the source project' do
2018-03-17 18:26:18 +05:30
project.add_reporter(user)
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
finder = described_class.new(user, project_id: project.id)
expect(finder.execute.to_a).to be_empty
2016-09-13 17:45:13 +05:30
end
it 'does not return archived projects' do
2018-03-17 18:26:18 +05:30
reporter_project.add_reporter(user)
2018-11-18 11:00:15 +05:30
::Projects::UpdateService.new(reporter_project, user, archived: true).execute
2017-09-10 17:25:29 +05:30
other_reporter_project = create(:project)
2018-03-17 18:26:18 +05:30
other_reporter_project.add_reporter(user)
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
finder = described_class.new(user, project_id: project.id)
expect(finder.execute.to_a).to eq([other_reporter_project])
2016-09-13 17:45:13 +05:30
end
it 'does not return projects for which issues are disabled' do
2018-03-17 18:26:18 +05:30
reporter_project.add_reporter(user)
2020-10-24 23:57:45 +05:30
reporter_project.update!(issues_enabled: false)
2017-09-10 17:25:29 +05:30
other_reporter_project = create(:project)
2018-03-17 18:26:18 +05:30
other_reporter_project.add_reporter(user)
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
finder = described_class.new(user, project_id: project.id)
expect(finder.execute.to_a).to eq([other_reporter_project])
2016-09-13 17:45:13 +05:30
end
2016-09-29 09:46:39 +05:30
2020-04-22 19:07:51 +05:30
it 'returns a page of projects ordered by star count' do
2019-10-12 21:52:04 +05:30
stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2)
2016-09-29 09:46:39 +05:30
2020-04-22 19:07:51 +05:30
projects = [
create(:project, namespace: user.namespace, star_count: 1),
create(:project, namespace: user.namespace, star_count: 5),
create(:project, namespace: user.namespace)
]
2016-09-29 09:46:39 +05:30
2018-11-20 20:47:30 +05:30
finder = described_class.new(user, project_id: project.id)
page = finder.execute.to_a
2019-10-12 21:52:04 +05:30
expect(page.length).to eq(2)
2020-04-22 19:07:51 +05:30
expect(page).to eq([projects[1], projects[0]])
2016-09-13 17:45:13 +05:30
end
2018-11-20 20:47:30 +05:30
end
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
context 'search' do
2016-09-13 17:45:13 +05:30
it 'returns projects matching a search query' do
2019-10-12 21:52:04 +05:30
foo_project = create(:project, name: 'foo')
2018-11-18 11:00:15 +05:30
foo_project.add_maintainer(user)
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
wadus_project = create(:project, name: 'wadus')
2018-11-18 11:00:15 +05:30
wadus_project.add_maintainer(user)
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
expect(described_class.new(user, project_id: project.id).execute.to_a)
2020-10-24 23:57:45 +05:30
.to contain_exactly(foo_project, wadus_project)
2018-11-20 20:47:30 +05:30
expect(described_class.new(user, project_id: project.id, search: 'wadus').execute.to_a)
2020-10-24 23:57:45 +05:30
.to contain_exactly(wadus_project)
2016-09-13 17:45:13 +05:30
end
2020-04-22 19:07:51 +05:30
it 'allows searching by parent namespace' do
group = create(:group)
other_project = create(:project, group: group)
other_project.add_maintainer(user)
expect(described_class.new(user, project_id: project.id, search: group.name).execute.to_a)
.to contain_exactly(other_project)
end
2016-09-13 17:45:13 +05:30
end
end
end