2013-03-19 15:37:50 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ForkedProjectLink, "add link on fork" do
|
2017-01-26 22:44:58 +00:00
|
|
|
let(:project_from) { create(:project, :repository) }
|
2013-04-25 14:15:33 +00:00
|
|
|
let(:namespace) { create(:namespace) }
|
|
|
|
let(:user) { create(:user, namespace: namespace) }
|
2013-03-19 15:37:50 +00:00
|
|
|
|
|
|
|
before do
|
2016-09-19 18:28:41 +00:00
|
|
|
create(:project_member, :reporter, user: user, project: project_from)
|
2013-03-19 15:37:50 +00:00
|
|
|
@project_to = fork_project(project_from, user)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "project_to knows it is forked" do
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(@project_to.forked?).to be_truthy
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "project knows who it is forked from" do
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(@project_to.forked_from_project).to eq(project_from)
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-11 22:12:31 +00:00
|
|
|
describe '#forked?' do
|
2013-04-25 14:15:33 +00:00
|
|
|
let(:forked_project_link) { build(:forked_project_link) }
|
2017-01-26 22:44:58 +00:00
|
|
|
let(:project_from) { create(:project, :repository) }
|
2013-04-25 14:15:33 +00:00
|
|
|
let(:project_to) { create(:project, forked_project_link: forked_project_link) }
|
2013-03-19 15:37:50 +00:00
|
|
|
|
|
|
|
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-08-01 15:00:44 +00:00
|
|
|
it "project_to knows it is forked" do
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(project_to.forked?).to be_truthy
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "project_from is not forked" do
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(project_from.forked?).to be_falsey
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "project_to.destroy destroys fork_link" do
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(forked_project_link).to receive(:destroy)
|
2013-03-19 15:37:50 +00:00
|
|
|
project_to.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fork_project(from_project, user)
|
2015-05-21 21:49:06 +00:00
|
|
|
shell = double('gitlab_shell', fork_repository: true)
|
|
|
|
|
|
|
|
service = Projects::ForkService.new(from_project, user)
|
|
|
|
allow(service).to receive(:gitlab_shell).and_return(shell)
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2015-05-21 21:49:06 +00:00
|
|
|
service.execute
|
|
|
|
end
|