project_mover_spec.rb 1.78 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

describe Gitlab::ProjectMover do
  let(:base_path) { Rails.root.join('tmp', 'rspec-sandbox') }

  before do
    FileUtils.rm_rf base_path if File.exists? base_path

9
    Gitlab.config.gitolite.stub(repos_path: base_path)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    @project = create(:project)
  end

  after do
    FileUtils.rm_rf base_path
  end

  it "should move project to subdir" do
    mk_dir base_path, '', @project.path
    mover = Gitlab::ProjectMover.new(@project, '', 'opensource')

    mover.execute.should be_true
    moved?('opensource', @project.path).should be_true
  end

  it "should move project from one subdir to another" do
    mk_dir base_path, 'vsizov', @project.path
    mover = Gitlab::ProjectMover.new(@project, 'vsizov', 'randx')

    mover.execute.should be_true
    moved?('randx', @project.path).should be_true
  end

  it "should move project from subdir to base" do
    mk_dir base_path, 'vsizov', @project.path
    mover = Gitlab::ProjectMover.new(@project, 'vsizov', '')

    mover.execute.should be_true
    moved?('', @project.path).should be_true
  end

  it "should raise if destination exists" do
    mk_dir base_path, '', @project.path
    mk_dir base_path, 'vsizov', @project.path
    mover = Gitlab::ProjectMover.new(@project, 'vsizov', '')

    expect { mover.execute }.to raise_error(Gitlab::ProjectMover::ProjectMoveError)
  end

  it "should raise if move failed" do
    mk_dir base_path
    mover = Gitlab::ProjectMover.new(@project, 'vsizov', '')

    expect { mover.execute }.to raise_error(Gitlab::ProjectMover::ProjectMoveError)
  end


  def mk_dir base_path, namespace = '', project_path = ''
    FileUtils.mkdir_p File.join(base_path, namespace, project_path + ".git")
  end

  def moved? namespace, path
    File.exists?(File.join(base_path, namespace, path + '.git'))
  end
end