diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-30 13:35:33 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-30 13:35:33 +0300 |
commit | 0d715bcd812ca6c99884e117f28a400669aa8e57 (patch) | |
tree | 5690fa43c790af40c51441425b9d8be068d4139d /spec/support | |
parent | 4f07a6a99cab8f8ae3ad0a786a6cc9a837955c08 (diff) | |
parent | 4d373005968b8269a8d2fe56b7776820396127a4 (diff) | |
download | gitlab-ce-0d715bcd812ca6c99884e117f28a400669aa8e57.tar.gz |
Merge branch 'mr-on-fork' of https://github.com/karlhungus/gitlabhq into karlhungus-mr-on-fork
Conflicts:
app/views/projects/commit/show.html.haml
app/views/projects/compare/show.html.haml
app/views/projects/merge_requests/branch_from.js.haml
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/test_env.rb | 121 |
1 files changed, 103 insertions, 18 deletions
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 3230301eead..cae7ff88513 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -27,17 +27,41 @@ module TestEnv # Disable mailer for spinach tests disable_mailer if opts[:mailer] == false + setup_stubs - # Use tmp dir for FS manipulations - repos_path = Rails.root.join('tmp', 'test-git-base-path') - Gitlab.config.gitlab_shell.stub(repos_path: repos_path) - Gitlab::Git::Repository.stub(repos_path: repos_path) + clear_test_repo_dir if opts[:init_repos] == true + setup_test_repos(opts) if opts[:repos] == true + end + + def enable_observers + ActiveRecord::Base.observers.enable(:all) + end + + def disable_observers + ActiveRecord::Base.observers.disable(:all) + end + + def disable_mailer + NotificationService.any_instance.stub(mailer: double.as_null_object) + end + def enable_mailer + NotificationService.any_instance.unstub(:mailer) + end + def setup_stubs() + # Use tmp dir for FS manipulations + repos_path = testing_path() GollumWiki.any_instance.stub(:init_repo) do |path| create_temp_repo(File.join(repos_path, "#{path}.git")) end + Gitlab.config.gitlab_shell.stub(repos_path: repos_path) + + Gitlab.config.satellites.stub(path: satellite_path) + + Gitlab::Git::Repository.stub(repos_path: repos_path) + Gitlab::Shell.any_instance.stub( add_repository: true, mv_repository: true, @@ -50,22 +74,95 @@ module TestEnv Gitlab::Satellite::Satellite.any_instance.stub( exists?: true, destroy: true, - create: true + create: true, + lock_files_dir: repos_path ) MergeRequest.any_instance.stub( check_if_can_be_merged: true ) - Repository.any_instance.stub( size: 12.45 ) + end + + def clear_repo_dir(namespace, name) + setup_stubs + #Clean any .wiki.git that may have been created + FileUtils.rm_rf File.join(testing_path(), "#{name}.wiki.git") + end + + #Create a repo and it's satellite + def create_repo(namespace, name) + setup_stubs + repo = repo(namespace, name) + # Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq + system("ln -s -f #{seed_repo_path()} #{repo}") + create_satellite(repo, namespace, name) + end + + private + + def testing_path + Rails.root.join('tmp', 'test-git-base-path') + end + + def seed_repo_path + Rails.root.join('tmp', 'repositories', 'gitlabhq') + end + + def seed_satellite_path + Rails.root.join('tmp', 'satellite', 'gitlabhq') + end + + def satellite_path + "#{testing_path()}/satellite" + end + + def repo(namespace, name) + unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) + repo = File.join(testing_path(), "#{namespace.path}/#{name}.git") + else + repo = File.join(testing_path(), "#{name}.git") + end + end + + def satellite(namespace, name) + unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) + satellite_repo = File.join(satellite_path, namespace.path, name) + else + satellite_repo = File.join(satellite_path, name) + end + end + + def setup_test_repos(opts ={}) + create_repo(nil, 'gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('') + create_repo(nil, 'source_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('source_') + create_repo(nil, 'target_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('target_') + end + + def clear_test_repo_dir + setup_stubs + # Use tmp dir for FS manipulations + repos_path = testing_path() # Remove tmp/test-git-base-path FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path # Recreate tmp/test-git-base-path FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path + + #Since much more is happening in satellites + FileUtils.mkdir_p Gitlab.config.satellites.path + end + + # Create a testing satellite, and clone the source repo into it + def create_satellite(source_repo, namespace, satellite_name) + satellite_repo = satellite(namespace, satellite_name) + # Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already + satellite_dir = File.dirname(satellite_repo) + FileUtils.mkdir_p satellite_dir unless File.exists?(satellite_dir) + system("ln -s -f #{seed_satellite_path()} #{satellite_repo}") end def create_temp_repo(path) @@ -73,16 +170,4 @@ module TestEnv command = "git init --quiet --bare #{path};" system(command) end - - def enable_observers - ActiveRecord::Base.observers.enable(:all) - end - - def disable_observers - ActiveRecord::Base.observers.disable(:all) - end - - def disable_mailer - NotificationService.any_instance.stub(mailer: double.as_null_object) - end end |