Commit 262f3f2f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'move-ee-specific-factories-to-ee-spec' into 'master'

[EE] Move EE-specific factories to ee/spec

See merge request gitlab-org/gitlab-ee!9557
parents 8aa046e7 5a3a20e8
# frozen_string_literal: true
FactoryBot.modify do
factory :board do
sequence(:name) { |n| "board#{n}" }
end
end
# frozen_string_literal: true
FactoryBot.modify do
factory :group do
project_creation_level ::EE::Gitlab::Access::MAINTAINER_PROJECT_ACCESS
end
end
FactoryBot.define do
factory :group_with_members, parent: :group do
after(:create) do |group, evaluator|
group.add_developer(create :user)
end
end
factory :group_with_ldap, parent: :group do
transient do
cn 'group1'
group_access Gitlab::Access::GUEST
provider 'ldapmain'
end
factory :group_with_ldap_group_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
cn: evaluator.cn,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end
factory :group_with_ldap_group_filter_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
filter: '(a=b)',
cn: nil,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end
end
end
# frozen_string_literal: true
FactoryBot.modify do
factory :import_state do
trait :mirror do
transient do
mirror true
import_url { generate(:url) }
end
before(:create) do |import_state, evaluator|
project = import_state.project
project.update_columns(mirror: evaluator.mirror,
import_url: evaluator.import_url,
mirror_user_id: project.creator_id)
end
end
after(:build) do |import_state|
case import_state.status.to_sym
when :scheduled
import_state.last_update_scheduled_at = Time.now
when :started
import_state.last_update_started_at = Time.now
when :finished
timestamp = Time.now
import_state.last_update_at = timestamp
import_state.last_update_started_at = timestamp
when :failed
import_state.last_update_at = Time.now
end
end
trait :hard_failed do
status :failed
retry_count { Gitlab::Mirror::MAX_RETRY + 1 }
last_update_at { Time.now - 1.minute }
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.modify do
factory :merge_request do
trait :with_approver do
after :create do |merge_request|
create :approver, target: merge_request
end
end
end
end
FactoryBot.define do FactoryBot.define do
factory :merge_request_with_approver, parent: :merge_request, traits: [:with_approver]
factory :ee_merge_request, parent: :merge_request do factory :ee_merge_request, parent: :merge_request do
trait :with_license_management_reports do trait :with_license_management_reports do
after(:build) do |merge_request| after(:build) do |merge_request|
......
# frozen_string_literal: true
FactoryBot.modify do
factory :namespace do
transient do
plan nil
end
before(:create) do |namespace, evaluator|
if evaluator.plan.present?
namespace.plan = create(evaluator.plan)
end
end
trait :with_build_minutes do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 400.minutes.to_i
end
trait :with_build_minutes_limit do
shared_runners_minutes_limit 500
end
trait :with_not_used_build_minutes_limit do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 300.minutes.to_i
shared_runners_minutes_limit 500
end
trait :with_used_build_minutes_limit do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 1000.minutes.to_i
shared_runners_minutes_limit 500
end
end
end
...@@ -6,6 +6,10 @@ FactoryBot.modify do ...@@ -6,6 +6,10 @@ FactoryBot.modify do
noteable { create(:epic) } noteable { create(:epic) }
project nil project nil
end end
trait :with_review do
review
end
end end
end end
......
# frozen_string_literal: true
FactoryBot.modify do
factory :project do
transient do
last_update_at nil
last_successful_update_at nil
retry_count 0
end
after(:create) do |project, evaluator|
import_state = project.import_state
if import_state
import_state.last_successful_update_at = evaluator.last_successful_update_at
import_state.retry_count = evaluator.retry_count
case import_state.status.to_sym
when :scheduled
import_state.last_update_scheduled_at = Time.now
when :started
import_state.last_update_started_at = Time.now
when :finished
timestamp = evaluator.last_update_at || Time.now
import_state.last_update_at = timestamp
import_state.last_successful_update_at = timestamp
when :failed
import_state.last_update_at = evaluator.last_update_at || Time.now
end
import_state.save!
end
end
trait :import_none do
import_status :none
end
trait :import_hard_failed do
import_status :failed
last_update_at { Time.now - 1.minute }
retry_count { Gitlab::Mirror::MAX_RETRY + 1 }
end
trait :disabled_mirror do
mirror false
import_url { generate(:url) }
mirror_user_id { creator_id }
end
trait :mirror do
mirror true
import_url { generate(:url) }
mirror_user_id { creator_id }
end
trait :random_last_repository_updated_at do
last_repository_updated_at { rand(1.year).seconds.ago }
end
end
end
# frozen_string_literal: true
FactoryBot.modify do
factory :protected_branch do
transient do
authorize_user_to_push nil
authorize_user_to_merge nil
authorize_user_to_unprotect nil
authorize_group_to_push nil
authorize_group_to_merge nil
authorize_group_to_unprotect nil
end
after(:build) do |protected_branch, evaluator|
# Clear access levels set in CE
protected_branch.push_access_levels.clear
protected_branch.merge_access_levels.clear
if user = evaluator.authorize_user_to_push
protected_branch.push_access_levels.new(user: user)
end
if user = evaluator.authorize_user_to_merge
protected_branch.merge_access_levels.new(user: user)
end
if user = evaluator.authorize_user_to_unprotect
protected_branch.unprotect_access_levels.new(user: user)
end
if group = evaluator.authorize_group_to_push
protected_branch.push_access_levels.new(group: group)
end
if group = evaluator.authorize_group_to_merge
protected_branch.merge_access_levels.new(group: group)
end
if group = evaluator.authorize_group_to_unprotect
protected_branch.unprotect_access_levels.new(group: group)
end
next unless protected_branch.merge_access_levels.empty?
if evaluator.default_access_level && evaluator.default_push_level
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
end
if evaluator.default_access_level && evaluator.default_merge_level
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
end
end
end
end
# frozen_string_literal: true
FactoryBot.modify do
factory :protected_tag do
transient do
authorize_user_to_create nil
authorize_group_to_create nil
end
trait :developers_can_create do
transient do
default_access_level false
end
after(:build) do |protected_tag|
protected_tag.create_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
end
end
trait :no_one_can_create do
transient do
default_access_level false
end
after(:build) do |protected_tag|
protected_tag.create_access_levels.new(access_level: Gitlab::Access::NO_ACCESS)
end
end
trait :maintainers_can_create do
transient do
default_access_level false
end
after(:build) do |protected_tag|
protected_tag.create_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
end
end
after(:build) do |protected_tag, evaluator|
if evaluator.authorize_user_to_create
protected_tag.create_access_levels.new(user: evaluator.authorize_user_to_create)
end
if evaluator.authorize_group_to_create
protected_tag.create_access_levels.new(group: evaluator.authorize_group_to_create)
end
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :gitlab_slack_application_service do
project
active true
type 'GitlabSlackApplicationService'
end
end
# frozen_string_literal: true
FactoryBot.modify do
factory :user do
trait :auditor do
auditor true
end
end
factory :omniauth_user do
transient do
saml_provider nil
end
end
end
FactoryBot.define do
factory :auditor, parent: :user, traits: [:auditor]
factory :external_user, parent: :user, traits: [:external]
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :appearance do factory :appearance do
title "GitLab Enterprise Edition" title "GitLab Community Edition"
description "Open source software to collaborate on code" description "Open source software to collaborate on code"
new_project_guidelines "Custom project guidelines" new_project_guidelines "Custom project guidelines"
end end
......
FactoryBot.define do FactoryBot.define do
factory :board do factory :board do
sequence(:name) { |n| "board#{n}" }
transient do transient do
project nil project nil
group nil group nil
......
...@@ -6,7 +6,7 @@ FactoryBot.define do ...@@ -6,7 +6,7 @@ FactoryBot.define do
ref 'master' ref 'master'
tag false tag false
created_at 'Di 29. Okt 09:50:00 CET 2013' created_at 'Di 29. Okt 09:50:00 CET 2013'
status :created status :success
pipeline factory: :ci_pipeline pipeline factory: :ci_pipeline
......
...@@ -4,15 +4,6 @@ FactoryBot.define do ...@@ -4,15 +4,6 @@ FactoryBot.define do
path { name.downcase.gsub(/\s/, '_') } path { name.downcase.gsub(/\s/, '_') }
type 'Group' type 'Group'
owner nil owner nil
project_creation_level ::EE::Gitlab::Access::MAINTAINER_PROJECT_ACCESS
after(:create) do |group|
if group.owner
# We could remove this after we have proper constraint:
# https://gitlab.com/gitlab-org/gitlab-ce/issues/43292
raise "Don't set owner for groups, use `group.add_owner(user)` instead"
end
end
after(:create) do |group| after(:create) do |group|
if group.owner if group.owner
...@@ -38,43 +29,6 @@ FactoryBot.define do ...@@ -38,43 +29,6 @@ FactoryBot.define do
avatar { fixture_file_upload('spec/fixtures/dk.png') } avatar { fixture_file_upload('spec/fixtures/dk.png') }
end end
factory :group_with_members do
after(:create) do |group, evaluator|
group.add_developer(create :user)
end
end
factory :group_with_ldap do
transient do
cn 'group1'
group_access Gitlab::Access::GUEST
provider 'ldapmain'
end
factory :group_with_ldap_group_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
cn: evaluator.cn,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end
factory :group_with_ldap_group_filter_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
filter: '(a=b)',
cn: nil,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end
end
trait :access_requestable do trait :access_requestable do
request_access_enabled true request_access_enabled true
end end
......
...@@ -12,51 +12,24 @@ FactoryBot.define do ...@@ -12,51 +12,24 @@ FactoryBot.define do
association :project, factory: [:project, :repository] association :project, factory: [:project, :repository]
end end
trait :mirror do
transient do
mirror true
import_url { generate(:url) }
end
before(:create) do |import_state, evaluator|
project = import_state.project
project.update_columns(mirror: evaluator.mirror,
import_url: evaluator.import_url,
mirror_user_id: project.creator_id)
end
end
trait :none do trait :none do
status :none status :none
end end
trait :scheduled do trait :scheduled do
status :scheduled status :scheduled
last_update_scheduled_at { Time.now }
end end
trait :started do trait :started do
status :started status :started
last_update_started_at { Time.now }
end end
trait :finished do trait :finished do
timestamp = Time.now
status :finished status :finished
last_update_at timestamp
last_successful_update_at timestamp
end end
trait :failed do trait :failed do
status :failed status :failed
last_update_at { Time.now }
end
trait :hard_failed do
status :failed
retry_count { Gitlab::Mirror::MAX_RETRY + 1 }
last_update_at { Time.now - 1.minute }
end end
after(:create) do |import_state, evaluator| after(:create) do |import_state, evaluator|
......
...@@ -68,12 +68,6 @@ FactoryBot.define do ...@@ -68,12 +68,6 @@ FactoryBot.define do
target_branch "master" target_branch "master"
end end
trait :with_approver do
after :create do |merge_request|
create :approver, target: merge_request
end
end
trait :rebased do trait :rebased do
source_branch "markdown" source_branch "markdown"
target_branch "improve/awesome" target_branch "improve/awesome"
...@@ -141,7 +135,6 @@ FactoryBot.define do ...@@ -141,7 +135,6 @@ FactoryBot.define do
factory :reopened_merge_request, traits: [:opened] factory :reopened_merge_request, traits: [:opened]
factory :invalid_merge_request, traits: [:invalid] factory :invalid_merge_request, traits: [:invalid]
factory :merge_request_with_diffs, traits: [:with_diffs] factory :merge_request_with_diffs, traits: [:with_diffs]
factory :merge_request_with_approver, traits: [:with_approver]
factory :merge_request_with_diff_notes do factory :merge_request_with_diff_notes do
after(:create) do |mr| after(:create) do |mr|
create(:diff_note_on_merge_request, noteable: mr, project: mr.source_project) create(:diff_note_on_merge_request, noteable: mr, project: mr.source_project)
......
...@@ -19,34 +19,5 @@ FactoryBot.define do ...@@ -19,34 +19,5 @@ FactoryBot.define do
owner.namespace = namespace owner.namespace = namespace
end end
end end
trait :with_build_minutes do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 400.minutes.to_i
end
trait :with_build_minutes_limit do
shared_runners_minutes_limit 500
end
trait :with_not_used_build_minutes_limit do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 300.minutes.to_i
shared_runners_minutes_limit 500
end
trait :with_used_build_minutes_limit do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 1000.minutes.to_i
shared_runners_minutes_limit 500
end
# EE-only
transient do
plan nil
end
before :create do |namespace, evaluator|
if evaluator.plan.present?
namespace.plan = create(evaluator.plan)
end
end
end end
end end
...@@ -137,10 +137,6 @@ FactoryBot.define do ...@@ -137,10 +137,6 @@ FactoryBot.define do
system true system true
end end
trait :with_review do
review
end
trait :downvote do trait :downvote do
note "thumbsdown" note "thumbsdown"
end end
......
...@@ -32,9 +32,6 @@ FactoryBot.define do ...@@ -32,9 +32,6 @@ FactoryBot.define do
group_runners_enabled nil group_runners_enabled nil
import_status nil import_status nil
import_jid nil import_jid nil
last_update_at nil
last_successful_update_at nil
retry_count 0
end end
after(:create) do |project, evaluator| after(:create) do |project, evaluator|
...@@ -73,9 +70,6 @@ FactoryBot.define do ...@@ -73,9 +70,6 @@ FactoryBot.define do
if evaluator.import_status if evaluator.import_status
import_state = project.import_state || project.build_import_state import_state = project.import_state || project.build_import_state
import_state.status = evaluator.import_status import_state.status = evaluator.import_status
import_state.last_update_at = evaluator.last_update_at
import_state.last_successful_update_at = evaluator.last_successful_update_at
import_state.retry_count = evaluator.retry_count
import_state.jid = evaluator.import_jid import_state.jid = evaluator.import_jid
import_state.save import_state.save
end end
...@@ -93,55 +87,20 @@ FactoryBot.define do ...@@ -93,55 +87,20 @@ FactoryBot.define do
visibility_level Gitlab::VisibilityLevel::PRIVATE visibility_level Gitlab::VisibilityLevel::PRIVATE
end end
trait :import_none do
import_status :none
end
trait :import_scheduled do trait :import_scheduled do
import_status :scheduled import_status :scheduled
after(:create) do |project, _|
project.import_state&.update_attributes(last_update_scheduled_at: Time.now)
end
end end
trait :import_started do trait :import_started do
import_status :started import_status :started
after(:create) do |project, _|
project.import_state&.update_attributes(last_update_started_at: Time.now)
end
end end
trait :import_finished do trait :import_finished do
timestamp = Time.now
import_status :finished import_status :finished
last_update_at timestamp
last_successful_update_at timestamp
end end
trait :import_failed do trait :import_failed do
import_status :failed import_status :failed
last_update_at { Time.now }
end
trait :import_hard_failed do
import_status :failed
last_update_at { Time.now - 1.minute }
retry_count { Gitlab::Mirror::MAX_RETRY + 1 }
end
trait :disabled_mirror do
mirror false
import_url { generate(:url) }
mirror_user_id { creator_id }
end
trait :mirror do
mirror true
import_url { generate(:url) }
mirror_user_id { creator_id }
end end
trait :archived do trait :archived do
...@@ -247,7 +206,6 @@ FactoryBot.define do ...@@ -247,7 +206,6 @@ FactoryBot.define do
url "http://foo.com" url "http://foo.com"
enabled true enabled true
end end
after(:create) do |project, evaluator| after(:create) do |project, evaluator|
project.remote_mirrors.create!(url: evaluator.url, enabled: evaluator.enabled) project.remote_mirrors.create!(url: evaluator.url, enabled: evaluator.enabled)
end end
...@@ -287,10 +245,6 @@ FactoryBot.define do ...@@ -287,10 +245,6 @@ FactoryBot.define do
end end
end end
trait :random_last_repository_updated_at do
last_repository_updated_at { rand(1.year).seconds.ago }
end
trait(:wiki_enabled) { wiki_access_level ProjectFeature::ENABLED } trait(:wiki_enabled) { wiki_access_level ProjectFeature::ENABLED }
trait(:wiki_disabled) { wiki_access_level ProjectFeature::DISABLED } trait(:wiki_disabled) { wiki_access_level ProjectFeature::DISABLED }
trait(:wiki_private) { wiki_access_level ProjectFeature::PRIVATE } trait(:wiki_private) { wiki_access_level ProjectFeature::PRIVATE }
......
...@@ -4,14 +4,6 @@ FactoryBot.define do ...@@ -4,14 +4,6 @@ FactoryBot.define do
project project
transient do transient do
# EE
authorize_user_to_push nil
authorize_user_to_merge nil
authorize_user_to_unprotect nil
authorize_group_to_push nil
authorize_group_to_merge nil
authorize_group_to_unprotect nil
default_push_level true default_push_level true
default_merge_level true default_merge_level true
default_access_level true default_access_level true
...@@ -58,33 +50,6 @@ FactoryBot.define do ...@@ -58,33 +50,6 @@ FactoryBot.define do
end end
after(:build) do |protected_branch, evaluator| after(:build) do |protected_branch, evaluator|
# EE
if user = evaluator.authorize_user_to_push
protected_branch.push_access_levels.new(user: user)
end
if user = evaluator.authorize_user_to_merge
protected_branch.merge_access_levels.new(user: user)
end
if user = evaluator.authorize_user_to_unprotect
protected_branch.unprotect_access_levels.new(user: user)
end
if group = evaluator.authorize_group_to_push
protected_branch.push_access_levels.new(group: group)
end
if group = evaluator.authorize_group_to_merge
protected_branch.merge_access_levels.new(group: group)
end
if group = evaluator.authorize_group_to_unprotect
protected_branch.unprotect_access_levels.new(group: group)
end
next unless protected_branch.merge_access_levels.empty?
if evaluator.default_access_level && evaluator.default_push_level if evaluator.default_access_level && evaluator.default_push_level
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER) protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
end end
......
...@@ -4,10 +4,6 @@ FactoryBot.define do ...@@ -4,10 +4,6 @@ FactoryBot.define do
project project
transient do transient do
# EE
authorize_user_to_create nil
authorize_group_to_create nil
default_access_level true default_access_level true
end end
...@@ -42,15 +38,6 @@ FactoryBot.define do ...@@ -42,15 +38,6 @@ FactoryBot.define do
end end
after(:build) do |protected_tag, evaluator| after(:build) do |protected_tag, evaluator|
# EE
if evaluator.authorize_user_to_create
protected_tag.create_access_levels.new(user: evaluator.authorize_user_to_create)
end
if evaluator.authorize_group_to_create
protected_tag.create_access_levels.new(group: evaluator.authorize_group_to_create)
end
if evaluator.default_access_level if evaluator.default_access_level
protected_tag.create_access_levels.new(access_level: Gitlab::Access::MAINTAINER) protected_tag.create_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
end end
......
...@@ -62,10 +62,4 @@ FactoryBot.define do ...@@ -62,10 +62,4 @@ FactoryBot.define do
project_key: 'jira-key' project_key: 'jira-key'
) )
end end
factory :gitlab_slack_application_service do
project
active true
type 'GitlabSlackApplicationService'
end
end end
...@@ -16,10 +16,6 @@ FactoryBot.define do ...@@ -16,10 +16,6 @@ FactoryBot.define do
admin true admin true
end end
trait :auditor do
auditor true
end
trait :blocked do trait :blocked do
after(:build) { |user, _| user.block! } after(:build) { |user, _| user.block! }
end end
...@@ -74,21 +70,22 @@ FactoryBot.define do ...@@ -74,21 +70,22 @@ FactoryBot.define do
transient do transient do
extern_uid '123456' extern_uid '123456'
provider 'ldapmain' provider 'ldapmain'
saml_provider nil
end end
after(:create) do |user, evaluator| after(:create) do |user, evaluator|
user.identities << create( identity_attrs = {
:identity,
provider: evaluator.provider, provider: evaluator.provider,
extern_uid: evaluator.extern_uid, extern_uid: evaluator.extern_uid
saml_provider: evaluator.saml_provider }
)
if evaluator.respond_to?(:saml_provider)
identity_attrs[:saml_provider] = evaluator.saml_provider
end
user.identities << create(:identity, identity_attrs)
end end
end end
factory :admin, traits: [:admin] factory :admin, traits: [:admin]
factory :auditor, traits: [:auditor]
factory :external_user, traits: [:external]
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment