2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ForkedProjectLink, "add link on fork" do
|
|
|
|
let(:project_from) { create(:project) }
|
|
|
|
let(:namespace) { create(:namespace) }
|
|
|
|
let(:user) { create(:user, namespace: namespace) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
@project_to = fork_project(project_from, user)
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "project_to knows it is forked" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@project_to.forked?).to be_truthy
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "project knows who it is forked from" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@project_to.forked_from_project).to eq(project_from)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#forked?' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:forked_project_link) { build(:forked_project_link) }
|
|
|
|
let(:project_from) { create(:project) }
|
|
|
|
let(:project_to) { create(:project, forked_project_link: forked_project_link) }
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
forked_project_link.forked_from_project = project_from
|
|
|
|
forked_project_link.forked_to_project = project_to
|
|
|
|
forked_project_link.save!
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "project_to knows it is forked" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(project_to.forked?).to be_truthy
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "project_from is not forked" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(project_from.forked?).to be_falsey
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "project_to.destroy destroys fork_link" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(forked_project_link).to receive(:destroy)
|
2014-09-02 18:07:02 +05:30
|
|
|
project_to.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fork_project(from_project, user)
|
2015-09-11 14:41:01 +05:30
|
|
|
shell = double('gitlab_shell', fork_repository: true)
|
|
|
|
|
|
|
|
service = Projects::ForkService.new(from_project, user)
|
|
|
|
allow(service).to receive(:gitlab_shell).and_return(shell)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
service.execute
|
|
|
|
end
|