diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-21 06:18:05 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-21 06:18:05 +0300 |
commit | e9be4b375bf2e4929ca82d06ff0dd4b62c5e9c44 (patch) | |
tree | 0c17cf52c34ef158f5ac05c10dd4829cc3da5fcd /spec/lib | |
parent | 47234ab3672697f85f8e9f452aea4453e1b9aadc (diff) | |
download | gitlab-ce-e9be4b375bf2e4929ca82d06ff0dd4b62c5e9c44.tar.gz |
Cover ProjectMover with tests
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/project_mover_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/lib/project_mover_spec.rb b/spec/lib/project_mover_spec.rb new file mode 100644 index 00000000000..af24635d82b --- /dev/null +++ b/spec/lib/project_mover_spec.rb @@ -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 |