summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gitlab_projects.rb8
-rw-r--r--spec/gitlab_projects_spec.rb17
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index ae8cb2d..83f542a 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -3,7 +3,7 @@ require 'fileutils'
require_relative 'gitlab_config'
class GitlabProjects
- attr_accessor :project_name
+ attr_reader :project_name, :full_path
def initialize
@command = ARGV.shift
@@ -25,12 +25,12 @@ class GitlabProjects
protected
def add_project
- FileUtils.mkdir_p(@full_path, mode: 0770)
- cmd = "cd #{@full_path} && git init --bare && ln -s #{@hook_path} #{@full_path}/hooks/post-receive"
+ FileUtils.mkdir_p(full_path, mode: 0770)
+ cmd = "cd #{full_path} && git init --bare && ln -s #{@hook_path} #{full_path}/hooks/post-receive"
system(cmd)
end
def rm_project
- FileUtils.rm_rf(@full_path)
+ FileUtils.rm_rf(full_path)
end
end
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index 95e4b92..4722a35 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -17,10 +17,21 @@ describe GitlabProjects do
before do
argv('add-project', 'gitlab-ci.git')
@gl_projects = GitlabProjects.new
+ @gl_projects.stub(full_path: tmp_repo_path)
+ end
+
+ after do
+ FileUtils.rm_rf(tmp_repo_path)
+ end
+
+ it "should create a directory" do
+ @gl_projects.stub(system: true)
+ @gl_projects.send :add_project
+ File.exists?(tmp_repo_path).should be_true
end
it "should receive valid cmd" do
- valid_cmd = "cd /home/git/repositories/gitlab-ci.git && git init --bare && ln -s /home/git/gitlab-shell/hooks/post-receive /home/git/repositories/gitlab-ci.git/hooks/post-receive"
+ valid_cmd = "cd #{tmp_repo_path} && git init --bare && ln -s /home/git/gitlab-shell/hooks/post-receive #{tmp_repo_path}/hooks/post-receive"
@gl_projects.should_receive(:system).with(valid_cmd)
@gl_projects.send :add_project
end
@@ -31,4 +42,8 @@ describe GitlabProjects do
ARGV[i] = arg
end
end
+
+ def tmp_repo_path
+ File.join(ROOT_PATH, 'tmp', 'gitlab-ci.git')
+ end
end