Cover ProjectMover with tests
This commit is contained in:
parent
47234ab367
commit
e9be4b375b
|
@ -32,7 +32,6 @@ module Gitlab
|
||||||
message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
|
message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
|
||||||
log_info "Error! #{message}"
|
log_info "Error! #{message}"
|
||||||
raise ProjectMoveError.new(message)
|
raise ProjectMoveError.new(message)
|
||||||
false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
65
spec/lib/project_mover_spec.rb
Normal file
65
spec/lib/project_mover_spec.rb
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
Gitlab.config.stub(git_base_path: base_path)
|
||||||
|
|
||||||
|
@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
|
|
@ -11,8 +11,8 @@ class Namespace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Gitlab::ProjectMover
|
#class Gitlab::ProjectMover
|
||||||
def execute
|
#def execute
|
||||||
true
|
#true
|
||||||
end
|
#end
|
||||||
end
|
#end
|
||||||
|
|
Loading…
Reference in a new issue