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
|
|
|
|
2014-02-25 12:21:53 -05:00
|
|
|
let(:project1) { create(:project) }
|
2014-04-03 04:47:56 -04:00
|
|
|
let(:project2) { create(:project, forked_from_project: project1) }
|
2016-11-27 05:33:15 -05:00
|
|
|
let(:project3) { create(:project, forked_from_project: project1, archived: true) }
|
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' }
|
2015-05-25 07:36:28 -04:00
|
|
|
merge_requests = MergeRequestsFinder.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' }
|
2015-05-25 07:36:28 -04:00
|
|
|
merge_requests = MergeRequestsFinder.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 }
|
|
|
|
merge_requests = MergeRequestsFinder.new(user, params).execute
|
|
|
|
expect(merge_requests.size).to eq(3)
|
|
|
|
end
|
2014-02-25 12:21:53 -05:00
|
|
|
end
|
|
|
|
end
|