2015-09-01 07:56:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RepositoryForkWorker do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:fork_project) { create(:project, forked_from_project: project) }
|
2016-03-18 14:31:19 +00:00
|
|
|
let(:shell) { Gitlab::Shell.new }
|
2015-09-01 07:56:40 +00:00
|
|
|
|
|
|
|
subject { RepositoryForkWorker.new }
|
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
before do
|
|
|
|
allow(subject).to receive(:gitlab_shell).and_return(shell)
|
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
describe "#perform" do
|
|
|
|
it "creates a new repository from a fork" do
|
2016-03-18 14:31:19 +00:00
|
|
|
expect(shell).to receive(:fork_repository).with(
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2015-12-15 02:53:52 +00:00
|
|
|
project.path_with_namespace,
|
2016-07-26 21:22:13 +00:00
|
|
|
project.repository_storage_path,
|
2015-12-15 02:53:52 +00:00
|
|
|
fork_project.namespace.path
|
|
|
|
).and_return(true)
|
2015-09-01 07:56:40 +00:00
|
|
|
|
2015-12-15 02:53:52 +00:00
|
|
|
subject.perform(
|
|
|
|
project.id,
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2015-12-15 02:53:52 +00:00
|
|
|
project.path_with_namespace,
|
|
|
|
fork_project.namespace.path)
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
it 'flushes various caches' do
|
2016-06-22 21:04:51 +00:00
|
|
|
expect(shell).to receive(:fork_repository).with(
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2016-06-22 21:04:51 +00:00
|
|
|
project.path_with_namespace,
|
2016-07-26 21:22:13 +00:00
|
|
|
project.repository_storage_path,
|
2016-06-22 21:04:51 +00:00
|
|
|
fork_project.namespace.path
|
|
|
|
).and_return(true)
|
2016-02-16 16:31:37 +00:00
|
|
|
|
|
|
|
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches).
|
|
|
|
and_call_original
|
|
|
|
|
2016-03-18 14:31:19 +00:00
|
|
|
expect_any_instance_of(Repository).to receive(:expire_exists_cache).
|
|
|
|
and_call_original
|
|
|
|
|
2016-07-26 21:22:13 +00:00
|
|
|
subject.perform(project.id, '/test/path', project.path_with_namespace,
|
2016-02-16 16:31:37 +00:00
|
|
|
fork_project.namespace.path)
|
|
|
|
end
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
it "handles bad fork" do
|
2016-03-18 14:31:19 +00:00
|
|
|
expect(shell).to receive(:fork_repository).and_return(false)
|
|
|
|
|
|
|
|
expect(subject.logger).to receive(:error)
|
|
|
|
|
2015-12-15 02:53:52 +00:00
|
|
|
subject.perform(
|
|
|
|
project.id,
|
2016-07-26 21:22:13 +00:00
|
|
|
'/test/path',
|
2015-12-15 02:53:52 +00:00
|
|
|
project.path_with_namespace,
|
|
|
|
fork_project.namespace.path)
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|