Commit e9be4b375bf2e4929ca82d06ff0dd4b62c5e9c44
1 parent
47234ab3
Exists in
master
and in
4 other branches
Cover ProjectMover with tests
Showing
3 changed files
with
70 additions
and
6 deletions
Show diff stats
lib/gitlab/project_mover.rb
| ... | ... | @@ -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 | ... | ... |