BigW Consortium Gitlab

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

describe ForkedProjectLink, "add link on fork" do
4 5 6
  let(:project_from) { create(:project) }
  let(:namespace) { create(:namespace) }
  let(:user) { create(:user, namespace: namespace) }
7 8

  before do
9
    create(:project_member, :reporter, user: user, project: project_from)
10 11 12
    @project_to = fork_project(project_from, user)
  end

13
  it "project_to knows it is forked" do
14
    expect(@project_to.forked?).to be_truthy
15 16
  end

17
  it "project knows who it is forked from" do
18
    expect(@project_to.forked_from_project).to eq(project_from)
19 20 21
  end
end

22
describe '#forked?' do
23 24 25
  let(:forked_project_link) { build(:forked_project_link) }
  let(:project_from) { create(:project) }
  let(:project_to) { create(:project, forked_project_link: forked_project_link) }
26 27 28 29 30 31 32

  before :each do
    forked_project_link.forked_from_project = project_from
    forked_project_link.forked_to_project = project_to
    forked_project_link.save!
  end

33
  it "project_to knows it is forked" do
34
    expect(project_to.forked?).to be_truthy
35 36
  end

37
  it "project_from is not forked" do
38
    expect(project_from.forked?).to be_falsey
39 40
  end

41
  it "project_to.destroy destroys fork_link" do
42
    expect(forked_project_link).to receive(:destroy)
43 44 45 46 47
    project_to.destroy
  end
end

def fork_project(from_project, user)
48 49 50 51
  shell = double('gitlab_shell', fork_repository: true)

  service = Projects::ForkService.new(from_project, user)
  allow(service).to receive(:gitlab_shell).and_return(shell)
52

53 54
  service.execute
end