2014-02-25 17:21:53 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequestsFinder do
|
2014-03-19 07:55:59 +00:00
|
|
|
let(:user) { create :user }
|
2014-02-25 17:21:53 +00:00
|
|
|
let(:user2) { create :user }
|
2014-03-19 07:55:59 +00:00
|
|
|
|
2017-01-25 21:49:52 +00: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 07:55:59 +00:00
|
|
|
|
2014-04-03 08:47:56 +00: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 07:55:59 +00:00
|
|
|
let!(:merge_request3) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project2) }
|
2016-11-27 10:33:15 +00:00
|
|
|
let!(:merge_request4) { create(:merge_request, :simple, author: user, source_project: project3, target_project: project3) }
|
2014-02-25 17:21:53 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
project1.team << [user, :master]
|
|
|
|
project2.team << [user, :developer]
|
2016-11-27 10:33:15 +00:00
|
|
|
project3.team << [user, :developer]
|
2014-02-25 17:21:53 +00:00
|
|
|
project2.team << [user2, :developer]
|
|
|
|
end
|
|
|
|
|
2014-03-19 07:55:59 +00:00
|
|
|
describe "#execute" do
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'filters by scope' do
|
2014-02-25 17:21:53 +00:00
|
|
|
params = { scope: 'authored', state: 'opened' }
|
2017-05-01 15:13:33 +00:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2016-11-27 10:33:15 +00:00
|
|
|
expect(merge_requests.size).to eq(3)
|
2014-02-25 17:21:53 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'filters by project' do
|
2014-02-25 17:21:53 +00:00
|
|
|
params = { project_id: project1.id, scope: 'authored', state: 'opened' }
|
2017-05-01 15:13:33 +00:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(merge_requests.size).to eq(1)
|
2014-02-25 17:21:53 +00:00
|
|
|
end
|
2016-11-27 10:33:15 +00:00
|
|
|
|
|
|
|
it 'filters by non_archived' do
|
|
|
|
params = { non_archived: true }
|
2017-05-01 15:13:33 +00:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2016-11-27 10:33:15 +00:00
|
|
|
expect(merge_requests.size).to eq(3)
|
|
|
|
end
|
2017-02-17 18:28:32 +00:00
|
|
|
|
|
|
|
it 'filters by iid' do
|
|
|
|
params = { project_id: project1.id, iids: merge_request1.iid }
|
|
|
|
|
2017-05-01 15:13:33 +00:00
|
|
|
merge_requests = described_class.new(user, params).execute
|
2017-02-17 18:28:32 +00:00
|
|
|
|
|
|
|
expect(merge_requests).to contain_exactly(merge_request1)
|
|
|
|
end
|
2014-02-25 17:21:53 +00:00
|
|
|
end
|
|
|
|
end
|