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

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

7
  let(:project1) { create(:project) }
8
  let(:project2) { create(:project, forked_from_project: project1) }
9

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

  before do
    project1.team << [user, :master]
    project2.team << [user, :developer]
    project2.team << [user2, :developer]
  end

20
  describe "#execute" do
21 22 23
    it 'should filter by scope' do
      params = { scope: 'authored', state: 'opened' }
      merge_requests = MergeRequestsFinder.new.execute(user, params)
24
      merge_requests.size.should == 2
25 26 27 28 29 30 31 32 33
    end

    it 'should filter by project' do
      params = { project_id: project1.id, scope: 'authored', state: 'opened' }
      merge_requests = MergeRequestsFinder.new.execute(user, params)
      merge_requests.size.should == 1
    end
  end
end