Welcome to mirror list, hosted at ThFree Co, Russian Federation.

merge_request_target_project_finder_spec.rb « finders « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08fbfd7229aec3ff9bd9278d904aa36f263bc99e (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe MergeRequestTargetProjectFinder do
  include ProjectForksHelper

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

  subject(:finder) { described_class.new(current_user: user, source_project: forked_project) }

  shared_examples 'finding related projects' do
    it 'finds sibling projects and base project' do
      other_fork

      expect(finder.execute).to contain_exactly(base_project, other_fork, forked_project)
    end

    it 'does not include projects that have merge requests turned off by default' do
      other_fork.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
      base_project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)

      expect(finder.execute).to contain_exactly(forked_project)
    end

    it 'includes projects that have merge requests turned off by default with a more-permissive project feature' do
      finder = described_class.new(current_user: user, source_project: forked_project, project_feature: :repository)

      other_fork.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
      base_project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)

      expect(finder.execute).to contain_exactly(base_project, other_fork, forked_project)
    end

    it 'does not contain archived projects' do
      base_project.update!(archived: true)

      expect(finder.execute).to contain_exactly(other_fork, forked_project)
    end

    it 'does not include routes by default' do
      row = finder.execute.first

      expect(row.association(:route).loaded?).to be_falsey
      expect(row.association(:namespace).loaded?).to be_falsey
      expect(row.namespace.association(:route).loaded?).to be_falsey
    end

    it 'includes routes when requested' do
      row = finder.execute(include_routes: true).first

      expect(row.association(:route).loaded?).to be_truthy
      expect(row.association(:namespace).loaded?).to be_truthy
      expect(row.namespace.association(:route).loaded?).to be_truthy
    end
  end

  context 'public projects' do
    let(:base_project) { create(:project, :public, path: 'base') }
    let(:forked_project) { fork_project(base_project) }
    let(:other_fork) { fork_project(base_project) }

    it_behaves_like 'finding related projects'
  end

  context 'private projects' do
    let(:base_project) { create(:project, :private, path: 'base') }
    let(:forked_project) { fork_project(base_project, base_project.owner) }
    let(:other_fork) { fork_project(base_project, base_project.owner) }

    context 'when the user is a member of all projects' do
      before do
        base_project.add_developer(user)
        forked_project.add_developer(user)
        other_fork.add_developer(user)
      end

      it_behaves_like 'finding related projects'
    end

    it 'only finds the projects the user is a member of' do
      other_fork.add_developer(user)
      base_project.add_developer(user)

      expect(finder.execute).to contain_exactly(other_fork, base_project)
    end
  end
end