summaryrefslogtreecommitdiff
path: root/spec/finders/fork_projects_finder_spec.rb
blob: 2b2e4c0d618fad6af3871b6ca542ee51b8da8287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ForkProjectsFinder do
  include ProjectForksHelper

  let(:source_project) { create(:project, :public, :empty_repo) }
  let(:private_fork) { fork_project(source_project, nil, name: 'A') }
  let(:internal_fork) { fork_project(source_project, nil, name: 'B') }
  let(:public_fork) { fork_project(source_project, nil, name: 'C') }

  let(:non_member) { create(:user) }
  let(:private_fork_member) { create(:user) }

  before do
    private_fork.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
    private_fork.add_developer(private_fork_member)

    internal_fork.update!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
  end

  describe '#execute' do
    let(:finder) { described_class.new(source_project, params: {}, current_user: current_user) }

    subject { finder.execute }

    describe 'without a user' do
      let(:current_user) { nil }

      it { is_expected.to eq([public_fork]) }
    end

    describe 'with a user' do
      let(:current_user) { non_member }

      it { is_expected.to eq([public_fork, internal_fork]) }
    end

    describe 'with a member' do
      let(:current_user) { private_fork_member }

      it { is_expected.to eq([public_fork, internal_fork, private_fork]) }
    end
  end
end