debian-mirror-gitlab/spec/factories/issues.rb

88 lines
2.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2020-04-22 19:07:51 +05:30
factory :issue, traits: [:has_internal_id] do
2017-08-17 22:00:37 +05:30
title { generate(:title) }
2017-09-10 17:25:29 +05:30
project
2018-03-17 18:26:18 +05:30
author { project.creator }
2018-11-08 19:23:39 +05:30
updated_by { author }
2019-12-26 22:10:19 +05:30
relative_position { RelativePositioning::START_POSITION }
2020-10-24 23:57:45 +05:30
issue_type { :issue }
2021-11-11 11:23:49 +05:30
association :work_item_type, :default
2016-06-02 11:05:42 +05:30
trait :confidential do
2019-12-21 20:55:43 +05:30
confidential { true }
2016-06-02 11:05:42 +05:30
end
2021-06-08 01:23:25 +05:30
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-08-17 22:00:37 +05:30
trait :opened do
2019-12-21 20:55:43 +05:30
state_id { Issue.available_states[:opened] }
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
trait :locked do
2019-12-21 20:55:43 +05:30
discussion_locked { true }
2018-12-05 23:21:45 +05:30
end
2016-06-02 11:05:42 +05:30
trait :closed do
2019-12-21 20:55:43 +05:30
state_id { Issue.available_states[:closed] }
2018-03-17 18:26:18 +05:30
closed_at { Time.now }
2016-06-02 11:05:42 +05:30
end
2020-11-24 15:15:51 +05:30
trait :with_alert do
after(:create) do |issue|
create(:alert_management_alert, project: issue.project, issue: issue)
end
end
2022-07-23 23:45:48 +05:30
trait :closed_as_duplicate do
closed
after(:create) do |issue|
issue.update!(duplicated_to: create(:issue, project: issue.project))
end
end
2019-12-21 20:55:43 +05:30
after(:build) do |issue, evaluator|
issue.state_id = Issue.available_states[evaluator.state]
end
2016-06-02 11:05:42 +05:30
factory :closed_issue, traits: [:closed]
2017-09-10 17:25:29 +05:30
factory :reopened_issue, traits: [:opened]
2016-09-13 17:45:13 +05:30
factory :labeled_issue do
transient do
2019-12-21 20:55:43 +05:30
labels { [] }
2016-09-13 17:45:13 +05:30
end
after(:create) do |issue, evaluator|
2020-10-24 23:57:45 +05:30
issue.update!(labels: evaluator.labels)
2016-09-13 17:45:13 +05:30
end
end
2020-10-24 23:57:45 +05:30
2022-06-21 17:19:12 +05:30
trait :task do
issue_type { :task }
association :work_item_type, :default, :task
end
2020-10-24 23:57:45 +05:30
factory :incident do
issue_type { :incident }
2021-11-11 11:23:49 +05:30
association :work_item_type, :default, :incident
2022-04-04 11:22:00 +05:30
# 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-10-24 23:57:45 +05:30
end
2016-06-02 11:05:42 +05:30
end
end