2013-04-11 16:54:20 -04:00
|
|
|
require 'rspec/mocks'
|
|
|
|
|
2013-04-01 07:39:19 -04:00
|
|
|
module TestEnv
|
|
|
|
extend self
|
|
|
|
|
|
|
|
# Test environment
|
|
|
|
#
|
2014-07-31 08:39:01 -04:00
|
|
|
# See gitlab.yml.example test section for paths
|
2013-04-01 07:39:19 -04:00
|
|
|
#
|
2013-04-10 16:28:42 -04:00
|
|
|
def init(opts = {})
|
2013-04-11 16:54:20 -04:00
|
|
|
RSpec::Mocks::setup(self)
|
|
|
|
|
2013-04-11 04:50:58 -04:00
|
|
|
# Disable mailer for spinach tests
|
|
|
|
disable_mailer if opts[:mailer] == false
|
|
|
|
|
2014-07-31 12:24:53 -04:00
|
|
|
# Clean /tmp/tests
|
|
|
|
tmp_test_path = Rails.root.join('tmp', 'tests')
|
2014-07-31 14:01:42 -04:00
|
|
|
|
|
|
|
if File.directory?(tmp_test_path)
|
|
|
|
FileUtils.rm_r(tmp_test_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir_p(tmp_test_path)
|
2014-07-31 12:24:53 -04:00
|
|
|
|
2014-07-31 12:35:07 -04:00
|
|
|
# Setup GitLab shell for test instance
|
|
|
|
setup_gitlab_shell
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
# Create repository for FactoryGirl.create(:project)
|
|
|
|
setup_factory_repo
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2013-06-07 16:39:32 -04:00
|
|
|
def disable_mailer
|
|
|
|
NotificationService.any_instance.stub(mailer: double.as_null_object)
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
2013-11-07 11:53:35 -05:00
|
|
|
|
2013-06-07 16:39:32 -04:00
|
|
|
def enable_mailer
|
|
|
|
NotificationService.any_instance.unstub(:mailer)
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def setup_gitlab_shell
|
|
|
|
unless File.directory?(Gitlab.config.gitlab_shell.path)
|
|
|
|
%x[rake gitlab:shell:install]
|
2013-04-01 09:04:35 -04:00
|
|
|
end
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
2013-04-01 07:39:19 -04:00
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def setup_factory_repo
|
|
|
|
repo_path = repos_path + "/root/testme.git"
|
2014-07-31 16:05:30 -04:00
|
|
|
clone_url = 'https://gitlab.com/gitlab-org/gitlab-test.git'
|
2013-04-25 10:15:33 -04:00
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
unless File.directory?(repo_path)
|
|
|
|
git_cmd = %W(git clone --bare #{clone_url} #{repo_path})
|
|
|
|
system(*git_cmd)
|
2013-11-12 09:11:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def copy_repo(project)
|
2014-07-31 14:30:35 -04:00
|
|
|
base_repo_path = File.expand_path(repos_path + "/root/testme.git")
|
|
|
|
target_repo_path = File.expand_path(repos_path + "/#{project.namespace.path}/#{project.path}.git")
|
|
|
|
FileUtils.mkdir_p(target_repo_path)
|
|
|
|
FileUtils.cp_r("#{base_repo_path}/.", target_repo_path)
|
|
|
|
FileUtils.chmod_R 0755, target_repo_path
|
2013-04-01 07:39:19 -04:00
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def repos_path
|
|
|
|
Gitlab.config.gitlab_shell.repos_path
|
2013-04-01 07:39:19 -04:00
|
|
|
end
|
|
|
|
end
|