2016-08-05 09:29:20 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MoveToProjectFinder do
|
|
|
|
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) }
|
|
|
|
let(:reporter_project) { create(:project) }
|
|
|
|
let(:developer_project) { create(:project) }
|
|
|
|
let(:master_project) { create(:project) }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
subject { described_class.new(user) }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
expect(subject.execute(project)).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns projects equal or above Gitlab::Access::REPORTER ordered by id in descending order' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
|
|
|
developer_project.add_developer(user)
|
|
|
|
master_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
expect(subject.execute(project).to_a).to eq([master_project, developer_project, reporter_project])
|
|
|
|
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
|
|
|
|
|
|
|
expect(subject.execute(project).to_a).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return archived projects' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
2017-01-19 01:35:50 -05:00
|
|
|
reporter_project.archive!
|
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
|
|
|
|
|
|
|
expect(subject.execute(project).to_a).to eq([other_reporter_project])
|
|
|
|
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)
|
2016-08-05 09:29:20 -04:00
|
|
|
reporter_project.update_attributes(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
|
|
|
|
|
|
|
expect(subject.execute(project).to_a).to eq([other_reporter_project])
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
it 'returns a page of projects ordered by id in descending order' do
|
|
|
|
stub_const 'MoveToProjectFinder::PAGE_SIZE', 2
|
|
|
|
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
|
|
|
developer_project.add_developer(user)
|
|
|
|
master_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
expect(subject.execute(project).to_a).to eq([master_project, developer_project])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns projects after the given offset id' do
|
|
|
|
stub_const 'MoveToProjectFinder::PAGE_SIZE', 2
|
|
|
|
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
|
|
|
developer_project.add_developer(user)
|
|
|
|
master_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
expect(subject.execute(project, search: nil, offset_id: master_project.id).to_a).to eq([developer_project, reporter_project])
|
|
|
|
expect(subject.execute(project, search: nil, offset_id: developer_project.id).to_a).to eq([reporter_project])
|
|
|
|
expect(subject.execute(project, search: nil, offset_id: reporter_project.id).to_a).to be_empty
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'search' do
|
|
|
|
it 'uses Project#search' do
|
|
|
|
expect(user).to receive_message_chain(:projects_where_can_admin_issues, :search) { Project.all }
|
|
|
|
|
|
|
|
subject.execute(project, search: 'wadus')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns projects matching a search query' do
|
2017-08-02 15:55:11 -04:00
|
|
|
foo_project = create(:project)
|
2017-12-22 03:18:28 -05:00
|
|
|
foo_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
wadus_project = create(:project, name: 'wadus')
|
2017-12-22 03:18:28 -05:00
|
|
|
wadus_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
expect(subject.execute(project).to_a).to eq([wadus_project, foo_project])
|
|
|
|
expect(subject.execute(project, search: 'wadus').to_a).to eq([wadus_project])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|