Put running playoff matches in a playoff stage (only on first level)

This commit is contained in:
Daniel Schädler 2019-05-09 20:56:30 +02:00
parent b5d71f33ca
commit bfaa270808
1 changed files with 4 additions and 1 deletions

View File

@ -16,12 +16,15 @@ FactoryBot.define do
factory :playoff_stage do factory :playoff_stage do
level { rand(10) } level { rand(10) }
transient do transient do
match_state { :not_started }
match_count { 4 } match_count { 4 }
end end
after(:create) do |stage, evaluator| after(:create) do |stage, evaluator|
# match_count -1 automatically generates 2 ^ stage.level matches # match_count -1 automatically generates 2 ^ stage.level matches
# (as this would be the amount of stages present in the real world) # (as this would be the amount of stages present in the real world)
stage.matches = create_list(:match, evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count) stage.matches = create_list(:running_playoff_match,
evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count,
state: evaluator.match_state)
stage.matches.each_with_index { |match, i| match.position = i } stage.matches.each_with_index { |match, i| match.position = i }
end end
end end