diff options
Diffstat (limited to 'spec/factories')
33 files changed, 173 insertions, 131 deletions
diff --git a/spec/factories/boards.rb b/spec/factories/boards.rb index 4df9aef2846..1ec042a6ab4 100644 --- a/spec/factories/boards.rb +++ b/spec/factories/boards.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :board do - project factory: :empty_project + project after(:create) do |board| board.lists.create(list_type: :closed) diff --git a/spec/factories/ci/pipeline_schedule.rb b/spec/factories/ci/pipeline_schedule.rb index a716da46ac6..564fef6833b 100644 --- a/spec/factories/ci/pipeline_schedule.rb +++ b/spec/factories/ci/pipeline_schedule.rb @@ -5,7 +5,7 @@ FactoryGirl.define do ref 'master' active true description "pipeline schedule" - project factory: :empty_project + project trait :nightly do cron '0 1 * * *' diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 35803f0c37f..e83a0e599a8 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -5,7 +5,7 @@ FactoryGirl.define do sha '97de212e80737a608d939f648d959671fb0a0142' status 'pending' - project factory: :empty_project + project factory :ci_pipeline_without_jobs do after(:build) do |pipeline| diff --git a/spec/factories/ci/runner_projects.rb b/spec/factories/ci/runner_projects.rb index 33a17cf7ed5..fa76d0ecd8c 100644 --- a/spec/factories/ci/runner_projects.rb +++ b/spec/factories/ci/runner_projects.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :ci_runner_project, class: Ci::RunnerProject do runner factory: :ci_runner - project factory: :empty_project + project end end diff --git a/spec/factories/ci/variables.rb b/spec/factories/ci/variables.rb index f83366136fd..d8fd513ffcf 100644 --- a/spec/factories/ci/variables.rb +++ b/spec/factories/ci/variables.rb @@ -7,6 +7,6 @@ FactoryGirl.define do protected true end - project factory: :empty_project + project end end diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb index 89e260cf65b..f4f12a095fc 100644 --- a/spec/factories/commits.rb +++ b/spec/factories/commits.rb @@ -3,7 +3,7 @@ require_relative '../support/repo_helpers' FactoryGirl.define do factory :commit do git_commit RepoHelpers.sample_commit - project factory: :empty_project + project initialize_with do new(git_commit, project) diff --git a/spec/factories/conversational_development_index_metrics.rb b/spec/factories/conversational_development_index_metrics.rb index a5412629195..3806c43ba15 100644 --- a/spec/factories/conversational_development_index_metrics.rb +++ b/spec/factories/conversational_development_index_metrics.rb @@ -2,32 +2,42 @@ FactoryGirl.define do factory :conversational_development_index_metric, class: ConversationalDevelopmentIndex::Metric do leader_issues 9.256 instance_issues 1.234 + percentage_issues 13.331 leader_notes 30.33333 instance_notes 28.123 + percentage_notes 92.713 leader_milestones 16.2456 instance_milestones 1.234 + percentage_milestones 7.595 leader_boards 5.2123 instance_boards 3.254 + percentage_boards 62.429 leader_merge_requests 1.2 instance_merge_requests 0.6 + percentage_merge_requests 50.0 leader_ci_pipelines 12.1234 instance_ci_pipelines 2.344 + percentage_ci_pipelines 19.334 leader_environments 3.3333 instance_environments 2.2222 + percentage_environments 66.672 leader_deployments 1.200 instance_deployments 0.771 + percentage_deployments 64.25 leader_projects_prometheus_active 0.111 instance_projects_prometheus_active 0.109 + percentage_projects_prometheus_active 98.198 leader_service_desk_issues 15.891 instance_service_desk_issues 13.345 + percentage_service_desk_issues 83.978 end end diff --git a/spec/factories/deploy_keys_projects.rb b/spec/factories/deploy_keys_projects.rb index 75f8982ecd9..27cece487bd 100644 --- a/spec/factories/deploy_keys_projects.rb +++ b/spec/factories/deploy_keys_projects.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :deploy_keys_project do deploy_key - project factory: :empty_project + project end end diff --git a/spec/factories/deployments.rb b/spec/factories/deployments.rb index 29ad1af9fd9..e5abfd67d60 100644 --- a/spec/factories/deployments.rb +++ b/spec/factories/deployments.rb @@ -10,6 +10,10 @@ FactoryGirl.define do after(:build) do |deployment, evaluator| deployment.project ||= deployment.environment.project + + unless deployment.project.repository_exists? + allow(deployment.project.repository).to receive(:fetch_ref) + end end end end diff --git a/spec/factories/environments.rb b/spec/factories/environments.rb index d8d699fb3aa..9034476d094 100644 --- a/spec/factories/environments.rb +++ b/spec/factories/environments.rb @@ -2,12 +2,10 @@ FactoryGirl.define do factory :environment, class: Environment do sequence(:name) { |n| "environment#{n}" } - project factory: :empty_project + association :project, :repository sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" } trait :with_review_app do |environment| - project - transient do ref 'master' end diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 55727d6b62c..ad9f7e2caef 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -1,7 +1,8 @@ FactoryGirl.define do factory :event do - project factory: :empty_project + project author factory: :user + action Event::JOINED trait(:created) { action Event::CREATED } trait(:updated) { action Event::UPDATED } @@ -20,4 +21,19 @@ FactoryGirl.define do target factory: :closed_issue end end + + factory :push_event, class: PushEvent do + project factory: :project_empty_repo + author factory: :user + action Event::PUSHED + end + + factory :push_event_payload do + event + commit_count 1 + action :pushed + ref_type :branch + ref 'master' + commit_to '3cdce97ed87c91368561584e7358f4d46e3e173c' + end end diff --git a/spec/factories/file_uploaders.rb b/spec/factories/file_uploaders.rb index d397dd705a5..622571390d2 100644 --- a/spec/factories/file_uploaders.rb +++ b/spec/factories/file_uploaders.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :file_uploader do skip_create - project factory: :empty_project + project secret nil transient do diff --git a/spec/factories/forked_project_links.rb b/spec/factories/forked_project_links.rb index 66b0f248959..9b34651a4ae 100644 --- a/spec/factories/forked_project_links.rb +++ b/spec/factories/forked_project_links.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :forked_project_link do - association :forked_to_project, factory: :project - association :forked_from_project, factory: :project + association :forked_to_project, factory: [:project, :repository] + association :forked_from_project, factory: [:project, :repository] after(:create) do |link| link.forked_from_project.reload @@ -9,7 +9,7 @@ FactoryGirl.define do end trait :forked_to_empty_project do - association :forked_to_project, factory: :empty_project + association :forked_to_project, factory: [:project, :repository] end end end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index a16695cb7c1..7c3b80198f9 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :issue do title { generate(:title) } author - project factory: :empty_project + project trait :confidential do confidential true diff --git a/spec/factories/label_priorities.rb b/spec/factories/label_priorities.rb index f25939d2d3e..7430466fc57 100644 --- a/spec/factories/label_priorities.rb +++ b/spec/factories/label_priorities.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :label_priority do - project factory: :empty_project + project label sequence(:priority) end diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb index 22c2a1f15e2..416317d677b 100644 --- a/spec/factories/labels.rb +++ b/spec/factories/labels.rb @@ -5,7 +5,7 @@ FactoryGirl.define do end factory :label, traits: [:base_label], class: ProjectLabel do - project factory: :empty_project + project transient do priority nil diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 1bc530d06db..cbec716d6ea 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -68,6 +68,17 @@ FactoryGirl.define do merge_user author end + after(:build) do |merge_request| + target_project = merge_request.target_project + source_project = merge_request.source_project + + # Fake `write_ref` if we don't have repository + # We have too many existing tests replying on this behaviour + unless [target_project, source_project].all?(&:repository_exists?) + allow(merge_request).to receive(:write_ref) + end + end + factory :merged_merge_request, traits: [:merged] factory :closed_merge_request, traits: [:closed] factory :reopened_merge_request, traits: [:opened] diff --git a/spec/factories/milestones.rb b/spec/factories/milestones.rb index 113665ff11b..2f75bf12cd7 100644 --- a/spec/factories/milestones.rb +++ b/spec/factories/milestones.rb @@ -17,7 +17,7 @@ FactoryGirl.define do state "closed" end - after(:build) do |milestone, evaluator| + after(:build, :stub) do |milestone, evaluator| if evaluator.group milestone.group = evaluator.group elsif evaluator.group_id @@ -27,7 +27,7 @@ FactoryGirl.define do elsif evaluator.project_id milestone.project_id = evaluator.project_id else - milestone.project = create(:empty_project) + milestone.project = create(:project) end end diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 046974dcd6e..f0d05504b7e 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -4,7 +4,7 @@ include ActionDispatch::TestProcess FactoryGirl.define do factory :note do - project factory: :empty_project + project note { generate(:title) } author on_issue diff --git a/spec/factories/notification_settings.rb b/spec/factories/notification_settings.rb index b5e96d18b8f..e9171528d86 100644 --- a/spec/factories/notification_settings.rb +++ b/spec/factories/notification_settings.rb @@ -1,8 +1,7 @@ FactoryGirl.define do factory :notification_setting do - source factory: :empty_project + source factory: :project user level 3 - events [] end end diff --git a/spec/factories/project_group_links.rb b/spec/factories/project_group_links.rb index 50341d943f5..e73cc05f9d7 100644 --- a/spec/factories/project_group_links.rb +++ b/spec/factories/project_group_links.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :project_group_link do - project factory: :empty_project + project group end end diff --git a/spec/factories/project_hooks.rb b/spec/factories/project_hooks.rb index d754e980931..accae636a3a 100644 --- a/spec/factories/project_hooks.rb +++ b/spec/factories/project_hooks.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :project_hook do url { generate(:url) } enable_ssl_verification false - project factory: :empty_project + project trait :token do token { SecureRandom.hex(10) } diff --git a/spec/factories/project_members.rb b/spec/factories/project_members.rb index fe4518caadf..9cf3a1e8e8a 100644 --- a/spec/factories/project_members.rb +++ b/spec/factories/project_members.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :project_member do user - project factory: :empty_project + project master trait(:guest) { access_level ProjectMember::GUEST } diff --git a/spec/factories/project_wikis.rb b/spec/factories/project_wikis.rb index ae222d5e69a..38fcab7466d 100644 --- a/spec/factories/project_wikis.rb +++ b/spec/factories/project_wikis.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :project_wiki do skip_create - project factory: :empty_project + project user factory: :user initialize_with { new(project, user) } end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 485ed48d2de..4a2034b31b3 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -5,15 +5,50 @@ FactoryGirl.define do # # Project does not have bare repository. # Use this factory if you don't need repository in tests - factory :empty_project, class: 'Project' do + factory :project, class: 'Project' do sequence(:name) { |n| "project#{n}" } path { name.downcase.gsub(/\s/, '_') } - namespace - creator - # Behaves differently to nil due to cache_has_external_issue_tracker has_external_issue_tracker false + # Associations + namespace + creator { group ? create(:user) : namespace&.owner } + + # Nest Project Feature attributes + transient do + wiki_access_level ProjectFeature::ENABLED + builds_access_level ProjectFeature::ENABLED + snippets_access_level ProjectFeature::ENABLED + issues_access_level ProjectFeature::ENABLED + merge_requests_access_level ProjectFeature::ENABLED + repository_access_level ProjectFeature::ENABLED + end + + after(:create) do |project, evaluator| + # Builds and MRs can't have higher visibility level than repository access level. + builds_access_level = [evaluator.builds_access_level, evaluator.repository_access_level].min + merge_requests_access_level = [evaluator.merge_requests_access_level, evaluator.repository_access_level].min + + project.project_feature.update_columns( + wiki_access_level: evaluator.wiki_access_level, + builds_access_level: builds_access_level, + snippets_access_level: evaluator.snippets_access_level, + issues_access_level: evaluator.issues_access_level, + merge_requests_access_level: merge_requests_access_level, + repository_access_level: evaluator.repository_access_level) + + # Normally the class Projects::CreateService is used for creating + # projects, and this class takes care of making sure the owner and current + # user have access to the project. Our specs don't use said service class, + # thus we must manually refresh things here. + unless project.group || project.pending_delete + project.add_master(project.owner) + end + + project.group&.refresh_members_authorized_projects + end + trait :public do visibility_level Gitlab::VisibilityLevel::PUBLIC end @@ -54,8 +89,46 @@ FactoryGirl.define do avatar { File.open(Rails.root.join('spec/fixtures/dk.png')) } end + trait :broken_storage do + after(:create) do |project| + project.update_column(:repository_storage, 'broken') + end + end + + # Test repository - https://gitlab.com/gitlab-org/gitlab-test trait :repository do - # no-op... for now! + path { 'gitlabhq' } + + test_repo + + transient do + create_templates nil + end + + after :create do |project, evaluator| + if evaluator.create_templates + templates_path = "#{evaluator.create_templates}_templates" + + project.repository.create_file( + project.creator, + ".gitlab/#{templates_path}/bug.md", + 'something valid', + message: 'test 3', + branch_name: 'master') + project.repository.create_file( + project.creator, + ".gitlab/#{templates_path}/template_test.md", + 'template_test', + message: 'test 1', + branch_name: 'master') + project.repository.create_file( + project.creator, + ".gitlab/#{templates_path}/feature_proposal.md", + 'feature_proposal', + message: 'test 2', + branch_name: 'master') + end + end end trait :empty_repo do @@ -64,7 +137,7 @@ FactoryGirl.define do # We delete hooks so that gitlab-shell will not try to authenticate with # an API that isn't running - FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.path_with_namespace}.git", 'hooks')) + FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.disk_path}.git", 'hooks')) end end @@ -72,7 +145,7 @@ FactoryGirl.define do after(:create) do |project| raise "Failed to create repository!" unless project.create_repository - FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.path_with_namespace}.git", 'refs')) + FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.disk_path}.git", 'refs')) end end @@ -102,103 +175,24 @@ FactoryGirl.define do trait(:repository_enabled) { repository_access_level ProjectFeature::ENABLED } trait(:repository_disabled) { repository_access_level ProjectFeature::DISABLED } trait(:repository_private) { repository_access_level ProjectFeature::PRIVATE } - - # Nest Project Feature attributes - transient do - wiki_access_level ProjectFeature::ENABLED - builds_access_level ProjectFeature::ENABLED - snippets_access_level ProjectFeature::ENABLED - issues_access_level ProjectFeature::ENABLED - merge_requests_access_level ProjectFeature::ENABLED - repository_access_level ProjectFeature::ENABLED - end - - after(:create) do |project, evaluator| - # Builds and MRs can't have higher visibility level than repository access level. - builds_access_level = [evaluator.builds_access_level, evaluator.repository_access_level].min - merge_requests_access_level = [evaluator.merge_requests_access_level, evaluator.repository_access_level].min - - project.project_feature - .update_attributes!( - wiki_access_level: evaluator.wiki_access_level, - builds_access_level: builds_access_level, - snippets_access_level: evaluator.snippets_access_level, - issues_access_level: evaluator.issues_access_level, - merge_requests_access_level: merge_requests_access_level, - repository_access_level: evaluator.repository_access_level - ) - - # Normally the class Projects::CreateService is used for creating - # projects, and this class takes care of making sure the owner and current - # user have access to the project. Our specs don't use said service class, - # thus we must manually refresh things here. - owner = project.owner - - if owner && owner.is_a?(User) && !project.pending_delete - project.members.create!(user: owner, access_level: Gitlab::Access::MASTER) - end - - project.group&.refresh_members_authorized_projects - end end # Project with empty repository # # This is a case when you just created a project # but not pushed any code there yet - factory :project_empty_repo, parent: :empty_project do + factory :project_empty_repo, parent: :project do empty_repo end # Project with broken repository # # Project with an invalid repository state - factory :project_broken_repo, parent: :empty_project do + factory :project_broken_repo, parent: :project do broken_repo end - # Project with test repository - # - # Test repository source can be found at - # https://gitlab.com/gitlab-org/gitlab-test - factory :project, parent: :empty_project do - path { 'gitlabhq' } - - test_repo - - transient do - create_template nil - end - - after :create do |project, evaluator| - if evaluator.create_template - args = evaluator.create_template - - project.add_user(args[:user], args[:access]) - - project.repository.create_file( - args[:user], - ".gitlab/#{args[:path]}/bug.md", - 'something valid', - message: 'test 3', - branch_name: 'master') - project.repository.create_file( - args[:user], - ".gitlab/#{args[:path]}/template_test.md", - 'template_test', - message: 'test 1', - branch_name: 'master') - project.repository.create_file( - args[:user], - ".gitlab/#{args[:path]}/feature_proposal.md", - 'feature_proposal', - message: 'test 2', - branch_name: 'master') - end - end - end - - factory :forked_project_with_submodules, parent: :empty_project do + factory :forked_project_with_submodules, parent: :project do path { 'forked-gitlabhq' } after :create do |project| @@ -228,11 +222,11 @@ FactoryGirl.define do jira_service end - factory :kubernetes_project, parent: :empty_project do + factory :kubernetes_project, parent: :project do kubernetes_service end - factory :prometheus_project, parent: :empty_project do + factory :prometheus_project, parent: :project do after :create do |project| project.create_prometheus_service( active: true, diff --git a/spec/factories/protected_branches.rb b/spec/factories/protected_branches.rb index 3dbace4b38a..fe0cbfc4444 100644 --- a/spec/factories/protected_branches.rb +++ b/spec/factories/protected_branches.rb @@ -57,5 +57,11 @@ FactoryGirl.define do protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MASTER) end end + + trait :no_one_can_merge do + after(:create) do |protected_branch| + protected_branch.merge_access_levels.first.update!(access_level: Gitlab::Access::NO_ACCESS) + end + end end end diff --git a/spec/factories/releases.rb b/spec/factories/releases.rb index 6a6d6fa171f..74497dc82c0 100644 --- a/spec/factories/releases.rb +++ b/spec/factories/releases.rb @@ -2,6 +2,6 @@ FactoryGirl.define do factory :release do tag "v1.1.0" description "Awesome release" - project factory: :empty_project + project end end diff --git a/spec/factories/sent_notifications.rb b/spec/factories/sent_notifications.rb index 99253be5a22..c2febf5b438 100644 --- a/spec/factories/sent_notifications.rb +++ b/spec/factories/sent_notifications.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :sent_notification do - project factory: :empty_project + project recipient factory: :user noteable { create(:issue, project: project) } reply_key { SentNotification.reply_key } diff --git a/spec/factories/services.rb b/spec/factories/services.rb index 30bc25cf88a..c2674ce2d11 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -1,11 +1,11 @@ FactoryGirl.define do factory :service do - project factory: :empty_project + project type 'Service' end factory :custom_issue_tracker_service, class: CustomIssueTrackerService do - project factory: :empty_project + project type 'CustomIssueTrackerService' category 'issue_tracker' active true @@ -17,7 +17,7 @@ FactoryGirl.define do end factory :kubernetes_service do - project factory: :empty_project + project active true properties({ api_url: 'https://kubernetes.example.com', @@ -26,7 +26,7 @@ FactoryGirl.define do end factory :prometheus_service do - project factory: :empty_project + project active true properties({ api_url: 'https://prometheus.example.com/' @@ -34,7 +34,7 @@ FactoryGirl.define do end factory :jira_service do - project factory: :empty_project + project active true properties( url: 'https://jira.example.com', @@ -43,7 +43,7 @@ FactoryGirl.define do end factory :hipchat_service do - project factory: :empty_project + project type 'HipchatService' token 'test_token' end diff --git a/spec/factories/snippets.rb b/spec/factories/snippets.rb index f6ce99d50f9..075bccd7f94 100644 --- a/spec/factories/snippets.rb +++ b/spec/factories/snippets.rb @@ -20,7 +20,7 @@ FactoryGirl.define do end factory :project_snippet, parent: :snippet, class: :ProjectSnippet do - project factory: :empty_project + project end factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do diff --git a/spec/factories/subscriptions.rb b/spec/factories/subscriptions.rb index b11b0a0a17b..1ae7fc9f384 100644 --- a/spec/factories/subscriptions.rb +++ b/spec/factories/subscriptions.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :subscription do user - project factory: :empty_project + project subscribable factory: :issue end end diff --git a/spec/factories/todos.rb b/spec/factories/todos.rb index c1ac3bb84ad..4975befbfe3 100644 --- a/spec/factories/todos.rb +++ b/spec/factories/todos.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :todo do - project factory: :empty_project + project author user target factory: :issue @@ -45,7 +45,7 @@ FactoryGirl.define do end factory :on_commit_todo, class: Todo do - project factory: :empty_project + project author user action { Todo::ASSIGNED } diff --git a/spec/factories/users.rb b/spec/factories/users.rb index e60fe713bc3..4000cd085b7 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - factory :user, aliases: [:author, :assignee, :recipient, :owner, :creator, :resource_owner] do + factory :user, aliases: [:author, :assignee, :recipient, :owner, :resource_owner] do email { generate(:email) } name { generate(:name) } username { generate(:username) } @@ -8,6 +8,10 @@ FactoryGirl.define do confirmation_token { nil } can_create_group true + after(:stub) do |user| + user.notification_email = user.email + end + before(:create) do |user| user.ensure_rss_token end |