BigW Consortium Gitlab

fork_network_spec.rb 1.96 KB
Newer Older
1
require 'spec_helper'
2

3 4 5 6 7 8 9 10 11 12 13 14
describe ForkNetwork do
  include ProjectForksHelper

  describe '#add_root_as_member' do
    it 'adds the root project as a member when creating a new root network' do
      project = create(:project)
      fork_network = described_class.create(root_project: project)

      expect(fork_network.projects).to include(project)
    end
  end

15 16 17 18 19 20 21 22 23 24 25 26
  describe '#find_fork_in' do
    it 'finds all fork of the current network in al collection' do
      network = create(:fork_network)
      root_project = network.root_project
      another_project = fork_project(root_project)
      create(:project)

      expect(network.find_forks_in(Project.all))
               .to contain_exactly(another_project, root_project)
    end
  end

27 28 29 30 31 32 33 34 35 36
  describe '#merge_requests' do
    it 'finds merge requests within the fork network' do
      project = create(:project)
      forked_project = fork_project(project)
      merge_request = create(:merge_request, source_project: forked_project, target_project: project)

      expect(project.fork_network.merge_requests).to include(merge_request)
    end
  end

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
  context 'for a deleted project' do
    it 'keeps the fork network' do
      project = create(:project, :public)
      forked = fork_project(project)
      project.destroy!

      fork_network = forked.reload.fork_network

      expect(fork_network.projects).to contain_exactly(forked)
      expect(fork_network.root_project).to be_nil
    end

    it 'allows multiple fork networks where the root project is deleted' do
      first_project = create(:project)
      second_project = create(:project)
      first_fork = fork_project(first_project)
      second_fork = fork_project(second_project)

      first_project.destroy
      second_project.destroy

      expect(first_fork.fork_network).not_to be_nil
      expect(first_fork.fork_network.root_project).to be_nil
      expect(second_fork.fork_network).not_to be_nil
      expect(second_fork.fork_network.root_project).to be_nil
    end
  end
64
end