Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
22817398
Commit
22817398
authored
Apr 01, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
define TestEnv and keep all global stubs in one place
parent
7bb71bb0
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
87 deletions
+72
-87
features/support/env.rb
features/support/env.rb
+3
-14
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+5
-1
spec/factories.rb
spec/factories.rb
+1
-1
spec/support/stubbed_repository.rb
spec/support/stubbed_repository.rb
+0
-71
spec/support/test_env.rb
spec/support/test_env.rb
+63
-0
No files found.
features/support/env.rb
View file @
22817398
...
...
@@ -14,7 +14,7 @@ require 'spinach/capybara'
require
'sidekiq/testing/inline'
%w(
stubbed_repository valid_commit select2_helper
)
.
each
do
|
f
|
%w(
valid_commit select2_helper test_env
)
.
each
do
|
f
|
require
Rails
.
root
.
join
(
'spec'
,
'support'
,
f
)
end
...
...
@@ -35,13 +35,8 @@ Capybara.default_wait_time = 10
DatabaseCleaner
.
strategy
=
:truncation
Spinach
.
hooks
.
before_scenario
do
# Use tmp dir for FS manipulations
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
Rails
.
root
.
join
(
'tmp'
,
'test-git-base-path'
))
Gitlab
::
Shell
.
any_instance
.
stub
(
:add_repository
)
do
|
path
|
create_temp_repo
(
"
#{
Rails
.
root
}
/tmp/test-git-base-path/
#{
path
}
.git"
)
end
FileUtils
.
rm_rf
Gitlab
.
config
.
gitlab_shell
.
repos_path
FileUtils
.
mkdir_p
Gitlab
.
config
.
gitlab_shell
.
repos_path
TestEnv
.
init
DatabaseCleaner
.
start
end
...
...
@@ -54,9 +49,3 @@ Spinach.hooks.before_run do
include
FactoryGirl
::
Syntax
::
Methods
end
def
create_temp_repo
(
path
)
FileUtils
.
mkdir_p
path
command
=
"git init --quiet --bare
#{
path
}
;"
system
(
command
)
end
lib/gitlab/git/repository.rb
View file @
22817398
...
...
@@ -34,7 +34,11 @@ module Gitlab
end
def
path_to_repo
@path_to_repo
||=
File
.
join
(
Gitlab
.
config
.
gitlab_shell
.
repos_path
,
"
#{
path_with_namespace
}
.git"
)
@path_to_repo
||=
File
.
join
(
repos_path
,
"
#{
path_with_namespace
}
.git"
)
end
def
repos_path
Gitlab
.
config
.
gitlab_shell
.
repos_path
end
def
repo
...
...
spec/factories.rb
View file @
22817398
...
...
@@ -25,7 +25,7 @@ FactoryGirl.define do
factory
:project
do
sequence
(
:name
)
{
|
n
|
"project
#{
n
}
"
}
path
{
name
.
downcase
.
gsub
(
/\s/
,
'_'
)
}
path
{
'gitlabhq'
}
creator
end
...
...
spec/support/stubbed_repository.rb
deleted
100644 → 0
View file @
7bb71bb0
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
spec/support/test_env.rb
0 → 100644
View file @
22817398
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment