diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/factories/iterations.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/factories/iterations.rb')
-rw-r--r-- | spec/factories/iterations.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/factories/iterations.rb b/spec/factories/iterations.rb new file mode 100644 index 00000000000..f6be1d9d752 --- /dev/null +++ b/spec/factories/iterations.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +FactoryBot.define do + sequence(:sequential_date) do |n| + n.days.from_now + end + + factory :iteration do + title + start_date { generate(:sequential_date) } + due_date { generate(:sequential_date) } + + transient do + project { nil } + group { nil } + project_id { nil } + group_id { nil } + resource_parent { nil } + end + + trait :upcoming do + state_enum { Iteration::STATE_ENUM_MAP[:upcoming] } + end + + trait :started do + state_enum { Iteration::STATE_ENUM_MAP[:started] } + end + + trait :closed do + state_enum { Iteration::STATE_ENUM_MAP[:closed] } + end + + trait(:skip_future_date_validation) do + after(:stub, :build) do |iteration| + iteration.skip_future_date_validation = true + end + end + + after(:build, :stub) do |iteration, evaluator| + if evaluator.group + iteration.group = evaluator.group + elsif evaluator.group_id + iteration.group_id = evaluator.group_id + elsif evaluator.project + iteration.project = evaluator.project + elsif evaluator.project_id + iteration.project_id = evaluator.project_id + elsif evaluator.resource_parent + id = evaluator.resource_parent.id + evaluator.resource_parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id + else + iteration.project = create(:project) + end + end + + factory :upcoming_iteration, traits: [:upcoming] + factory :started_iteration, traits: [:started] + factory :closed_iteration, traits: [:closed] + end +end |