summaryrefslogtreecommitdiff
path: root/spec/factories/boards.rb
blob: 9ea8f3ad06f4b1e5b81a6c8728c8894424cf7cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

FactoryBot.define do
  factory :board do
    transient do
      project { nil }
      group { nil }
      project_id { nil }
      group_id { nil }
      resource_parent { nil }
    end

    after(:build, :stub) do |board, evaluator|
      if evaluator.group
        board.group = evaluator.group
      elsif evaluator.group_id
        board.group_id = evaluator.group_id
      elsif evaluator.project
        board.project = evaluator.project
      elsif evaluator.project_id
        board.project_id = evaluator.project_id
      elsif evaluator.resource_parent
        id = evaluator.resource_parent.id
        evaluator.resource_parent.is_a?(Group) ? board.group_id = id : evaluator.project_id = id
      else
        board.project = create(:project, :empty_repo)
      end
    end

    after(:create) do |board|
      board.lists.create!(list_type: :closed)
    end
  end

  factory :group_board, parent: :board do
    group
  end
end