BigW Consortium Gitlab

merge_requests_finder_spec.rb 1.87 KB
Newer Older
1 2 3
require 'spec_helper'

describe MergeRequestsFinder do
4
  let(:user)  { create :user }
5
  let(:user2) { create :user }
6

7 8 9
  let(:project1) { create(:empty_project) }
  let(:project2) { create(:empty_project, forked_from_project: project1) }
  let(:project3) { create(:empty_project, :archived, forked_from_project: project1) }
10

11 12
  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') }
13
  let!(:merge_request3) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project2) }
14
  let!(:merge_request4) { create(:merge_request, :simple, author: user, source_project: project3, target_project: project3) }
15 16 17 18

  before do
    project1.team << [user, :master]
    project2.team << [user, :developer]
19
    project3.team << [user, :developer]
20 21 22
    project2.team << [user2, :developer]
  end

23
  describe "#execute" do
24
    it 'filters by scope' do
25
      params = { scope: 'authored', state: 'opened' }
26
      merge_requests = described_class.new(user, params).execute
27
      expect(merge_requests.size).to eq(3)
28 29
    end

30
    it 'filters by project' do
31
      params = { project_id: project1.id, scope: 'authored', state: 'opened' }
32
      merge_requests = described_class.new(user, params).execute
33
      expect(merge_requests.size).to eq(1)
34
    end
35 36 37

    it 'filters by non_archived' do
      params = { non_archived: true }
38
      merge_requests = described_class.new(user, params).execute
39 40
      expect(merge_requests.size).to eq(3)
    end
41 42 43 44

    it 'filters by iid' do
      params = { project_id: project1.id, iids: merge_request1.iid }

45
      merge_requests = described_class.new(user, params).execute
46 47 48

      expect(merge_requests).to contain_exactly(merge_request1)
    end
49 50
  end
end