BigW Consortium Gitlab

forked_project_link_spec.rb 1.43 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 9 10 11 12

  before do
    @project_to = fork_project(project_from, user)
  end

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

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

describe :forked_from_project do
22 23 24
  let(:forked_project_link) { build(:forked_project_link) }
  let(:project_from) { create(:project) }
  let(:project_to) { create(:project, forked_project_link: forked_project_link) }
25 26 27 28 29 30 31 32 33 34


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


  it "project_to should know it is forked" do
35
    expect(project_to.forked?).to be_truthy
36 37 38
  end

  it "project_from should not be forked" do
39
    expect(project_from.forked?).to be_falsey
40 41 42
  end

  it "project_to.destroy should destroy fork_link" do
43
    expect(forked_project_link).to receive(:destroy)
44 45 46 47 48 49
    project_to.destroy
  end

end

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

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

55 56
  service.execute
end