forked_project_link_spec.rb 1.67 KB
Newer Older
1 2 3
require 'spec_helper'

describe ForkedProjectLink, "add link on fork" do
4 5
  include ProjectForksHelper

6
  let(:project_from) { create(:project, :repository) }
7
  let(:project_to) { fork_project(project_from, user) }
8
  let(:user) { create(:user) }
9 10

  before do
11 12 13 14 15 16 17
    project_from.add_reporter(user)
  end

  it 'project_from knows its forks' do
    _ = project_to

    expect(project_from.forks.count).to eq(1)
18 19
  end

20
  it "project_to knows it is forked" do
21
    expect(project_to.forked?).to be_truthy
22 23
  end

24
  it "project knows who it is forked from" do
25
    expect(project_to.forked_from_project).to eq(project_from)
26 27
  end

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  context 'project_to is pending_delete' do
    before do
      project_to.update!(pending_delete: true)
    end

    it { expect(project_from.forks.count).to eq(0) }
  end

  context 'project_from is pending_delete' do
    before do
      project_from.update!(pending_delete: true)
    end

    it { expect(project_to.forked_from_project).to be_nil }
  end

44
  describe '#forked?' do
45
    let(:project_to) { create(:project, :repository, forked_project_link: forked_project_link) }
46
    let(:forked_project_link) { create(:forked_project_link) }
47

48 49 50 51 52
    before do
      forked_project_link.forked_from_project = project_from
      forked_project_link.forked_to_project = project_to
      forked_project_link.save!
    end
53

54 55 56
    it "project_to knows it is forked" do
      expect(project_to.forked?).to be_truthy
    end
57

58 59 60
    it "project_from is not forked" do
      expect(project_from.forked?).to be_falsey
    end
61

62 63
    it "project_to.destroy destroys fork_link" do
      project_to.destroy
64 65

      expect(ForkedProjectLink.exists?(id: forked_project_link.id)).to eq(false)
66
    end
67
  end
68
end