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) }
|
2017-07-04 10:48:25 +00:00
|
|
|
let(:project_to) { fork_project(project_from, user) }
|
2017-06-06 15:36:41 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:namespace) { user.namespace }
|
2013-03-19 15:37:50 +00:00
|
|
|
|
|
|
|
before do
|
2017-07-04 10:48:25 +00:00
|
|
|
project_from.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'project_from knows its forks' do
|
|
|
|
_ = project_to
|
|
|
|
|
|
|
|
expect(project_from.forks.count).to eq(1)
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "project_to knows it is forked" do
|
2017-07-04 10:48:25 +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
|
2017-07-04 10:48:25 +00:00
|
|
|
expect(project_to.forked_from_project).to eq(project_from)
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
|
2017-07-03 10:31:37 +00:00
|
|
|
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
|
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
describe '#forked?' do
|
|
|
|
let(:project_to) { create(:project, forked_project_link: forked_project_link) }
|
2017-05-30 11:54:59 +00:00
|
|
|
let(:forked_project_link) { create(:forked_project_link) }
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
before do
|
|
|
|
forked_project_link.forked_from_project = project_from
|
|
|
|
forked_project_link.forked_to_project = project_to
|
|
|
|
forked_project_link.save!
|
|
|
|
end
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
it "project_to knows it is forked" do
|
|
|
|
expect(project_to.forked?).to be_truthy
|
|
|
|
end
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
it "project_from is not forked" do
|
|
|
|
expect(project_from.forked?).to be_falsey
|
|
|
|
end
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
it "project_to.destroy destroys fork_link" do
|
|
|
|
project_to.destroy
|
2017-05-30 11:54:59 +00:00
|
|
|
|
|
|
|
expect(ForkedProjectLink.exists?(id: forked_project_link.id)).to eq(false)
|
2017-07-04 10:48:25 +00:00
|
|
|
end
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
def fork_project(from_project, user)
|
|
|
|
service = Projects::ForkService.new(from_project, user)
|
|
|
|
shell = double('gitlab_shell', fork_repository: true)
|
2015-05-21 21:49:06 +00:00
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
allow(service).to receive(:gitlab_shell).and_return(shell)
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2017-07-04 10:48:25 +00:00
|
|
|
service.execute
|
|
|
|
end
|
2015-05-21 21:49:06 +00:00
|
|
|
end
|