2014-02-25 12:21:53 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequestsFinder do
|
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
|
|
|
|
2017-01-25 16:49:52 -05:00
|
|
|
let(:project1) { create(:empty_project) }
|
|
|
|
let(:project2) { create(:empty_project, forked_from_project: project1) }
|
|
|
|
let(:project3) { create(:empty_project, :archived, forked_from_project: project1) }
|
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) }
|
|
|
|
let!(:merge_request2) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1, state: 'closed') }
|
2014-03-19 03:55:59 -04:00
|
|
|
let!(:merge_request3) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project2) }
|
2016-11-27 05:33:15 -05:00
|
|
|
let!(:merge_request4) { create(:merge_request, :simple, author: user, source_project: project3, target_project: project3) }
|
2014-02-25 12:21:53 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project1.team << [user, :master]
|
|
|
|
project2.team << [user, :developer]
|
2016-11-27 05:33:15 -05:00
|
|
|
project3.team << [user, :developer]
|
2014-02-25 12:21:53 -05:00
|
|
|
project2.team << [user2, :developer]
|
|
|
|
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
|
2016-11-27 05:33:15 -05: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
|
|
|
|
|
|
|
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
|
2016-11-27 05:33:15 -05:00
|
|
|
expect(merge_requests.size).to eq(3)
|
|
|
|
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
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|
|
|
|
end
|