2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2020-04-03 14:10:03 -04:00
|
|
|
factory :issue, traits: [:has_internal_id] do
|
2017-03-23 12:37:14 -04:00
|
|
|
title { generate(:title) }
|
2017-08-02 15:55:11 -04:00
|
|
|
project
|
2017-08-04 13:14:04 -04:00
|
|
|
author { project.creator }
|
2018-06-01 11:09:08 -04:00
|
|
|
updated_by { author }
|
2019-10-30 05:27:58 -04:00
|
|
|
relative_position { RelativePositioning::START_POSITION }
|
2020-07-23 23:09:19 -04:00
|
|
|
issue_type { :issue }
|
2021-09-10 11:11:12 -04:00
|
|
|
association :work_item_type, :default
|
2016-02-16 22:55:24 -05:00
|
|
|
|
2016-03-17 15:38:51 -04:00
|
|
|
trait :confidential do
|
2019-10-01 20:06:26 -04:00
|
|
|
confidential { true }
|
2016-03-17 15:38:51 -04:00
|
|
|
end
|
|
|
|
|
2021-04-27 17:10:09 -04:00
|
|
|
trait :with_asc_relative_position do
|
|
|
|
sequence(:relative_position) { |n| n * 1000 }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_desc_relative_position do
|
|
|
|
sequence(:relative_position) { |n| -n * 1000 }
|
|
|
|
end
|
|
|
|
|
2017-04-25 06:36:18 -04:00
|
|
|
trait :opened do
|
2019-10-18 07:11:44 -04:00
|
|
|
state_id { Issue.available_states[:opened] }
|
2017-04-25 06:36:18 -04:00
|
|
|
end
|
|
|
|
|
2018-09-20 10:41:15 -04:00
|
|
|
trait :locked do
|
2019-10-01 20:06:26 -04:00
|
|
|
discussion_locked { true }
|
2018-09-20 10:41:15 -04:00
|
|
|
end
|
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
trait :closed do
|
2019-10-18 07:11:44 -04:00
|
|
|
state_id { Issue.available_states[:closed] }
|
2017-09-19 11:25:42 -04:00
|
|
|
closed_at { Time.now }
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
|
2020-08-25 14:10:49 -04:00
|
|
|
trait :with_alert do
|
|
|
|
after(:create) do |issue|
|
|
|
|
create(:alert_management_alert, project: issue.project, issue: issue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-15 02:08:36 -04:00
|
|
|
trait :closed_as_duplicate do
|
|
|
|
closed
|
|
|
|
after(:create) do |issue|
|
|
|
|
issue.update!(duplicated_to: create(:issue, project: issue.project))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
after(:build) do |issue, evaluator|
|
|
|
|
issue.state_id = Issue.available_states[evaluator.state]
|
|
|
|
end
|
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
factory :closed_issue, traits: [:closed]
|
2017-07-19 10:03:50 -04:00
|
|
|
factory :reopened_issue, traits: [:opened]
|
2016-07-20 18:45:19 -04:00
|
|
|
|
|
|
|
factory :labeled_issue do
|
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
labels { [] }
|
2016-07-20 18:45:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |issue, evaluator|
|
2020-07-21 08:09:30 -04:00
|
|
|
issue.update!(labels: evaluator.labels)
|
2016-07-20 18:45:19 -04:00
|
|
|
end
|
|
|
|
end
|
2020-07-23 23:09:19 -04:00
|
|
|
|
2022-03-30 17:09:29 -04:00
|
|
|
trait :task do
|
|
|
|
issue_type { :task }
|
|
|
|
association :work_item_type, :default, :task
|
|
|
|
end
|
|
|
|
|
2020-07-23 23:09:19 -04:00
|
|
|
factory :incident do
|
|
|
|
issue_type { :incident }
|
2021-09-10 11:11:12 -04:00
|
|
|
association :work_item_type, :default, :incident
|
2022-02-15 07:14:49 -05:00
|
|
|
|
|
|
|
# An escalation status record is created for all incidents
|
|
|
|
# in app code. This is a trait to avoid creating escalation
|
|
|
|
# status records in specs which do not need them.
|
|
|
|
trait :with_escalation_status do
|
|
|
|
after(:create) do |incident|
|
|
|
|
create(:incident_management_issuable_escalation_status, issue: incident)
|
|
|
|
end
|
|
|
|
end
|
2020-07-23 23:09:19 -04:00
|
|
|
end
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
end
|