diff options
Diffstat (limited to 'spec/factories/projects.rb')
-rw-r--r-- | spec/factories/projects.rb | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index f113ca2425f..856f0f6cd05 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -8,8 +8,8 @@ FactoryBot.define do # Project does not have bare repository. # Use this factory if you don't need repository in tests factory :project, class: 'Project' do - sequence(:name) { |n| "project#{n}" } - path { name.downcase.gsub(/\s/, '_') } + sequence(:path) { |n| "project-#{n}" } + name { "#{path.humanize} Name" } # Behaves differently to nil due to cache_has_external_* methods. has_external_issue_tracker { false } @@ -222,7 +222,7 @@ FactoryBot.define do # 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' }) + # 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 @@ -245,6 +245,19 @@ FactoryBot.define do end end + # A basic repository with a single file 'test.txt'. It also has the HEAD as the default branch. + trait :small_repo do + custom_repo + + files { { 'test.txt' => 'test' } } + + after(:create) do |project| + Sidekiq::Worker.skipping_transaction_check do + raise "Failed to assign the repository head!" unless project.change_head(project.default_branch_or_main) + end + end + end + # Test repository - https://gitlab.com/gitlab-org/gitlab-test trait :repository do test_repo @@ -354,6 +367,18 @@ FactoryBot.define do end end + trait :stubbed_commit_count do + after(:build) do |project| + stub_method(project.repository, :commit_count) { 2 } + end + end + + trait :stubbed_branch_count do + after(:build) do |project| + stub_method(project.repository, :branch_count) { 2 } + end + end + trait :wiki_repo do after(:create) do |project| stub_feature_flags(main_branch_over_master: false) @@ -510,4 +535,11 @@ FactoryBot.define do trait :in_subgroup do namespace factory: [:group, :nested] end + + trait :readme do + custom_repo + + path { 'gitlab-profile' } + files { { 'README.md' => 'Hello World' } } + end end |