Commit e9be4b375bf2e4929ca82d06ff0dd4b62c5e9c44

Authored by Dmitriy Zaporozhets
1 parent 47234ab3

Cover ProjectMover with tests

lib/gitlab/project_mover.rb
... ... @@ -32,7 +32,6 @@ module Gitlab
32 32 message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
33 33 log_info "Error! #{message}"
34 34 raise ProjectMoveError.new(message)
35   - false
36 35 end
37 36 end
38 37  
... ...
spec/lib/project_mover_spec.rb 0 → 100644
... ... @@ -0,0 +1,65 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::ProjectMover do
  4 + let(:base_path) { Rails.root.join('tmp', 'rspec-sandbox') }
  5 +
  6 + before do
  7 + FileUtils.rm_rf base_path if File.exists? base_path
  8 +
  9 + Gitlab.config.stub(git_base_path: base_path)
  10 +
  11 + @project = create(:project)
  12 + end
  13 +
  14 + after do
  15 + FileUtils.rm_rf base_path
  16 + end
  17 +
  18 + it "should move project to subdir" do
  19 + mk_dir base_path, '', @project.path
  20 + mover = Gitlab::ProjectMover.new(@project, '', 'opensource')
  21 +
  22 + mover.execute.should be_true
  23 + moved?('opensource', @project.path).should be_true
  24 + end
  25 +
  26 + it "should move project from one subdir to another" do
  27 + mk_dir base_path, 'vsizov', @project.path
  28 + mover = Gitlab::ProjectMover.new(@project, 'vsizov', 'randx')
  29 +
  30 + mover.execute.should be_true
  31 + moved?('randx', @project.path).should be_true
  32 + end
  33 +
  34 + it "should move project from subdir to base" do
  35 + mk_dir base_path, 'vsizov', @project.path
  36 + mover = Gitlab::ProjectMover.new(@project, 'vsizov', '')
  37 +
  38 + mover.execute.should be_true
  39 + moved?('', @project.path).should be_true
  40 + end
  41 +
  42 + it "should raise if destination exists" do
  43 + mk_dir base_path, '', @project.path
  44 + mk_dir base_path, 'vsizov', @project.path
  45 + mover = Gitlab::ProjectMover.new(@project, 'vsizov', '')
  46 +
  47 + expect { mover.execute }.to raise_error(Gitlab::ProjectMover::ProjectMoveError)
  48 + end
  49 +
  50 + it "should raise if move failed" do
  51 + mk_dir base_path
  52 + mover = Gitlab::ProjectMover.new(@project, 'vsizov', '')
  53 +
  54 + expect { mover.execute }.to raise_error(Gitlab::ProjectMover::ProjectMoveError)
  55 + end
  56 +
  57 +
  58 + def mk_dir base_path, namespace = '', project_path = ''
  59 + FileUtils.mkdir_p File.join(base_path, namespace, project_path + ".git")
  60 + end
  61 +
  62 + def moved? namespace, path
  63 + File.exists?(File.join(base_path, namespace, path + '.git'))
  64 + end
  65 +end
... ...
spec/support/namespaces_stub.rb
... ... @@ -11,8 +11,8 @@ class Namespace
11 11 end
12 12 end
13 13  
14   -class Gitlab::ProjectMover
15   - def execute
16   - true
17   - end
18   -end
  14 +#class Gitlab::ProjectMover
  15 + #def execute
  16 + #true
  17 + #end
  18 +#end
... ...