summaryrefslogtreecommitdiff
path: root/spec/factories/projects.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-09-03 15:21:15 +0100
committerNick Thomas <nick@gitlab.com>2018-09-05 15:10:39 +0100
commitdb28db414c8ab3d253294e430cd99d14499fad2e (patch)
treeebb4a5c47cbcd5d923b26ea2a84b8f5e43bd1e57 /spec/factories/projects.rb
parentf7c1a5e1ed7003f9c35e9f81b94789562f968f57 (diff)
downloadgitlab-ce-db28db414c8ab3d253294e430cd99d14499fad2e.tar.gz
Allow repositories to be programmatically built in the specs
Diffstat (limited to 'spec/factories/projects.rb')
-rw-r--r--spec/factories/projects.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb
index 1215b04913e..17e457c04a5 100644
--- a/spec/factories/projects.rb
+++ b/spec/factories/projects.rb
@@ -130,6 +130,33 @@ FactoryBot.define do
end
end
+ # Build a custom repository by specifying a hash of `filename => content` in
+ # the transient `files` attribute. Each file will be created in its own
+ # commit, operating against the master branch. So, the following call:
+ #
+ # create(:project, :custom_repo, files: { 'foo/a.txt' => 'foo', 'b.txt' => bar' })
+ #
+ # will create a repository containing two files, and two commits, in master
+ trait :custom_repo do
+ transient do
+ files {}
+ end
+
+ after :create do |project, evaluator|
+ raise "Failed to create repository!" unless project.create_repository
+
+ evaluator.files.each do |filename, content|
+ project.repository.create_file(
+ project.creator,
+ filename,
+ content,
+ message: "Automatically created file #{filename}",
+ branch_name: 'master'
+ )
+ end
+ end
+ end
+
# Test repository - https://gitlab.com/gitlab-org/gitlab-test
trait :repository do
test_repo