2014-02-25 12:21:53 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequestsFinder do
|
2017-09-29 04:04:50 -04:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2014-03-19 03:55:59 -04:00
|
|
|
let(:user) { create :user }
|
2014-02-25 12:21:53 -05:00
|
|
|
let(:user2) { create :user }
|
2014-03-19 03:55:59 -04:00
|
|
|
|
2018-01-24 01:06:24 -05:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:subgroup) { create(:group, parent: group) }
|
|
|
|
let(:project1) { create(:project, :public, group: group) }
|
2017-09-29 04:04:50 -04:00
|
|
|
let(:project2) { fork_project(project1, user) }
|
|
|
|
let(:project3) do
|
|
|
|
p = fork_project(project1, user)
|
|
|
|
p.update!(archived: true)
|
|
|
|
p
|
|
|
|
end
|
2018-01-24 01:06:24 -05:00
|
|
|
let(:project4) { create(:project, :public, group: subgroup) }
|
2014-03-19 03:55:59 -04:00
|
|
|
|
2014-04-03 04:47:56 -04:00
|
|
|
let!(:merge_request1) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1) }
|
2018-02-23 11:04:20 -05:00
|
|
|
let!(:merge_request2) { create(:merge_request, :conflict, author: user, source_project: project2, target_project: project1, state: 'closed') }
|
2018-06-26 15:30:29 -04:00
|
|
|
let!(:merge_request3) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, state: 'locked') }
|
2016-11-27 05:33:15 -05:00
|
|
|
let!(:merge_request4) { create(:merge_request, :simple, author: user, source_project: project3, target_project: project3) }
|
2018-01-24 01:06:24 -05:00
|
|
|
let!(:merge_request5) { create(:merge_request, :simple, author: user, source_project: project4, target_project: project4) }
|
2014-02-25 12:21:53 -05:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project1.add_maintainer(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project2.add_developer(user)
|
|
|
|
project3.add_developer(user)
|
|
|
|
project2.add_developer(user2)
|
2018-01-24 01:06:24 -05:00
|
|
|
project4.add_developer(user)
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|
|
|
|
|
2014-03-19 03:55:59 -04:00
|
|
|
describe "#execute" do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'filters by scope' do
|
2014-02-25 12:21:53 -05:00
|
|
|
params = { scope: 'authored', state: 'opened' }
|
2017-05-01 11:13:33 -04:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2018-06-26 15:30:29 -04:00
|
|
|
expect(merge_requests.size).to eq(3)
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'filters by project' do
|
2014-02-25 12:21:53 -05:00
|
|
|
params = { project_id: project1.id, scope: 'authored', state: 'opened' }
|
2017-05-01 11:13:33 -04:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(merge_requests.size).to eq(1)
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|
2016-11-27 05:33:15 -05:00
|
|
|
|
2018-01-24 01:06:24 -05:00
|
|
|
it 'filters by group' do
|
|
|
|
params = { group_id: group.id }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests.size).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by group including subgroups', :nested_groups do
|
|
|
|
params = { group_id: group.id, include_subgroups: true }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests.size).to eq(3)
|
|
|
|
end
|
|
|
|
|
2016-11-27 05:33:15 -05:00
|
|
|
it 'filters by non_archived' do
|
|
|
|
params = { non_archived: true }
|
2017-05-01 11:13:33 -04:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2018-01-24 01:06:24 -05:00
|
|
|
expect(merge_requests.size).to eq(4)
|
2016-11-27 05:33:15 -05:00
|
|
|
end
|
2017-02-17 13:28:32 -05:00
|
|
|
|
|
|
|
it 'filters by iid' do
|
|
|
|
params = { project_id: project1.id, iids: merge_request1.iid }
|
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2017-02-17 13:28:32 -05:00
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(merge_request1)
|
|
|
|
end
|
2017-06-13 17:02:35 -04:00
|
|
|
|
2018-02-23 11:04:20 -05:00
|
|
|
it 'filters by source branch' do
|
|
|
|
params = { source_branch: merge_request2.source_branch }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(merge_request2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by target branch' do
|
|
|
|
params = { target_branch: merge_request2.target_branch }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(merge_request2)
|
|
|
|
end
|
|
|
|
|
2018-06-26 15:30:29 -04:00
|
|
|
it 'filters by state' do
|
|
|
|
params = { state: 'locked' }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(merge_request3)
|
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
context 'filtering by group milestone' do
|
|
|
|
let!(:group) { create(:group, :public) }
|
|
|
|
let(:group_milestone) { create(:milestone, group: group) }
|
|
|
|
let!(:group_member) { create(:group_member, group: group, user: user) }
|
|
|
|
let(:params) { { milestone_title: group_milestone.title } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project2.update(namespace: group)
|
|
|
|
merge_request2.update(milestone: group_milestone)
|
|
|
|
merge_request3.update(milestone: group_milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns issues assigned to that group milestone' do
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(merge_request2, merge_request3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-28 06:16:29 -05:00
|
|
|
context 'filtering by created_at/updated_at' do
|
2018-01-24 01:06:24 -05:00
|
|
|
let(:new_project) { create(:project, forked_from_project: project1) }
|
2017-06-13 17:02:35 -04:00
|
|
|
|
|
|
|
let!(:new_merge_request) do
|
|
|
|
create(:merge_request,
|
|
|
|
:simple,
|
|
|
|
author: user,
|
|
|
|
created_at: 1.week.from_now,
|
2018-02-28 06:16:29 -05:00
|
|
|
updated_at: 1.week.from_now,
|
2018-01-24 01:06:24 -05:00
|
|
|
source_project: new_project,
|
2018-02-28 06:16:29 -05:00
|
|
|
target_project: new_project)
|
2017-06-13 17:02:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:old_merge_request) do
|
|
|
|
create(:merge_request,
|
|
|
|
:simple,
|
|
|
|
author: user,
|
2018-02-28 06:16:29 -05:00
|
|
|
source_branch: 'feature_1',
|
2017-06-13 17:02:35 -04:00
|
|
|
created_at: 1.week.ago,
|
2018-02-28 06:16:29 -05:00
|
|
|
updated_at: 1.week.ago,
|
2018-01-24 01:06:24 -05:00
|
|
|
source_project: new_project,
|
|
|
|
target_project: new_project)
|
2017-06-13 17:02:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
new_project.add_maintainer(user)
|
2017-06-13 17:02:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by created_after' do
|
2018-02-28 06:16:29 -05:00
|
|
|
params = { project_id: new_project.id, created_after: new_merge_request.created_at }
|
2017-06-13 17:02:35 -04:00
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(new_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by created_before' do
|
2018-02-28 06:16:29 -05:00
|
|
|
params = { project_id: new_project.id, created_before: old_merge_request.created_at }
|
2017-06-13 17:02:35 -04:00
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(old_merge_request)
|
|
|
|
end
|
2018-02-28 06:16:29 -05:00
|
|
|
|
|
|
|
it 'filters by created_after and created_before' do
|
|
|
|
params = {
|
|
|
|
project_id: new_project.id,
|
|
|
|
created_after: old_merge_request.created_at,
|
|
|
|
created_before: new_merge_request.created_at
|
|
|
|
}
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(old_merge_request, new_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by updated_after' do
|
|
|
|
params = { project_id: new_project.id, updated_after: new_merge_request.updated_at }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(new_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by updated_before' do
|
|
|
|
params = { project_id: new_project.id, updated_before: old_merge_request.updated_at }
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(old_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by updated_after and updated_before' do
|
|
|
|
params = {
|
|
|
|
project_id: new_project.id,
|
|
|
|
updated_after: old_merge_request.updated_at,
|
|
|
|
updated_before: new_merge_request.updated_at
|
|
|
|
}
|
|
|
|
|
|
|
|
merge_requests = described_class.new(user, params).execute
|
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(old_merge_request, new_merge_request)
|
|
|
|
end
|
2017-06-13 17:02:35 -04:00
|
|
|
end
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|
2017-08-24 12:17:04 -04:00
|
|
|
|
|
|
|
describe '#row_count', :request_store do
|
|
|
|
it 'returns the number of rows for the default state' do
|
|
|
|
finder = described_class.new(user)
|
|
|
|
|
2018-06-26 15:30:29 -04:00
|
|
|
expect(finder.row_count).to eq(3)
|
2017-08-24 12:17:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the number of rows for a given state' do
|
|
|
|
finder = described_class.new(user, state: 'closed')
|
|
|
|
|
|
|
|
expect(finder.row_count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|