Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-01 15:39:19 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-01 15:39:19 +0400
commit22817398e6c1cf9a479fecd99c55369fd81717cb (patch)
tree6c385da37d215a2d1de9fe25383da996fecc2d55 /spec
parent7bb71bb088e17578482e7f934147b0fd11c7ad0e (diff)
define TestEnv and keep all global stubs in one place
Diffstat (limited to 'spec')
-rw-r--r--spec/factories.rb2
-rw-r--r--spec/support/stubbed_repository.rb71
-rw-r--r--spec/support/test_env.rb63
3 files changed, 64 insertions, 72 deletions
diff --git a/spec/factories.rb b/spec/factories.rb
index 41766859468..8f620cd7f79 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -25,7 +25,7 @@ FactoryGirl.define do
factory :project do
sequence(:name) { |n| "project#{n}" }
- path { name.downcase.gsub(/\s/, '_') }
+ path { 'gitlabhq' }
creator
end
diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb
deleted file mode 100644
index 3dfdb3539fb..00000000000
--- a/spec/support/stubbed_repository.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require "gitlab/git/repository"
-require "project"
-require "merge_request"
-require "shell"
-
-# Stubs out all Git repository access done by models so that specs can run
-# against fake repositories without Grit complaining that they don't exist.
-class Project
- def repository
- if path == "empty" || !path
- nil
- else
- GitLabTestRepo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq'), 'master')
- end
- end
-
- def satellite
- FakeSatellite.new
- end
-
- class FakeSatellite
- def exists?
- true
- end
-
- def destroy
- true
- end
-
- def create
- true
- end
- end
-end
-
-class MergeRequest
- def check_if_can_be_merged
- true
- end
-end
-
-class GitLabTestRepo < Repository
- # patch repo size (in mb)
- def size
- 12.45
- end
-end
-
-module Gitlab
- class Shell
- def add_repository name
- true
- end
-
- def mv_repository name, new_name
- true
- end
-
- def remove_repository name
- true
- end
-
- def add_key id, key
- true
- end
-
- def remove_key id, key
- true
- end
- end
-end
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
new file mode 100644
index 00000000000..769405b6ffb
--- /dev/null
+++ b/spec/support/test_env.rb
@@ -0,0 +1,63 @@
+module TestEnv
+ extend self
+
+ # Test environment
+ #
+ # all repositories and namespaces stored at
+ # RAILS_APP/tmp/test-git-base-path
+ #
+ # Next shell methods are stubbed and return true
+ # - mv_repository
+ # - remove_repository
+ # - add_key
+ # - remove_key
+ #
+ def init
+ # 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::Shell.any_instance.stub(
+ add_repository: ->(path) { create_temp_repo(File.join(repos_path, "#{path}.git")) },
+ mv_repository: true,
+ remove_repository: true,
+ add_key: true,
+ remove_key: true
+ )
+
+ fake_satellite = double(
+ exists?: true,
+ destroy: true,
+ create: true
+ )
+
+ Project.any_instance.stub(
+ satellite: fake_satellite
+ )
+
+ MergeRequest.any_instance.stub(
+ check_if_can_be_merged: true
+ )
+
+ Repository.any_instance.stub(
+ size: 12.45
+ )
+
+ # 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
+
+ # Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq
+ seed_repo = Rails.root.join('tmp', 'repositories', 'gitlabhq')
+ target_repo = File.join(repos_path, 'gitlabhq.git')
+ system("ln -s #{seed_repo} #{target_repo}")
+ end
+
+ def create_temp_repo(path)
+ FileUtils.mkdir_p path
+ command = "git init --quiet --bare #{path};"
+ system(command)
+ end
+end