BigW Consortium Gitlab

repository_fork_worker_spec.rb 1.62 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

describe RepositoryForkWorker do
  let(:project) { create(:project) }
  let(:fork_project) { create(:project, forked_from_project: project) }
6
  let(:shell) { Gitlab::Shell.new }
7 8 9

  subject { RepositoryForkWorker.new }

10 11 12 13
  before do
    allow(subject).to receive(:gitlab_shell).and_return(shell)
  end

14 15
  describe "#perform" do
    it "creates a new repository from a fork" do
16
      expect(shell).to receive(:fork_repository).with(
17
        '/test/path',
18
        project.path_with_namespace,
19
        project.repository_storage_path,
20 21
        fork_project.namespace.path
      ).and_return(true)
22

23 24
      subject.perform(
        project.id,
25
        '/test/path',
26 27
        project.path_with_namespace,
        fork_project.namespace.path)
28 29
    end

30
    it 'flushes various caches' do
31
      expect(shell).to receive(:fork_repository).with(
32
        '/test/path',
33
        project.path_with_namespace,
34
        project.repository_storage_path,
35 36
        fork_project.namespace.path
      ).and_return(true)
37 38 39 40

      expect_any_instance_of(Repository).to receive(:expire_emptiness_caches).
        and_call_original

41 42 43
      expect_any_instance_of(Repository).to receive(:expire_exists_cache).
        and_call_original

44
      subject.perform(project.id, '/test/path', project.path_with_namespace,
45 46 47
                      fork_project.namespace.path)
    end

48
    it "handles bad fork" do
49 50 51 52
      expect(shell).to receive(:fork_repository).and_return(false)

      expect(subject.logger).to receive(:error)

53 54
      subject.perform(
        project.id,
55
        '/test/path',
56 57
        project.path_with_namespace,
        fork_project.namespace.path)
58 59 60
    end
  end
end