Commit 4affea77 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ee-spec-factories-projects' into 'master'

Revert "Extract EE-specific code from spec/factories/projects.rb"

See merge request gitlab-org/gitlab-ee!9613
parents afdceea7 3b1bc547
# 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
...@@ -32,6 +32,9 @@ FactoryBot.define do ...@@ -32,6 +32,9 @@ 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|
...@@ -70,6 +73,9 @@ FactoryBot.define do ...@@ -70,6 +73,9 @@ 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
...@@ -87,20 +93,55 @@ FactoryBot.define do ...@@ -87,20 +93,55 @@ 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
...@@ -206,6 +247,7 @@ FactoryBot.define do ...@@ -206,6 +247,7 @@ 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
...@@ -245,6 +287,10 @@ FactoryBot.define do ...@@ -245,6 +287,10 @@ 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 }
......
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