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 7afb5ae552
commit cb82ca44d8
1 changed files with 4 additions and 1 deletions

View File

@ -16,12 +16,15 @@ FactoryBot.define do
factory :playoff_stage do
level { rand(10) }
transient do
match_state { :not_started }
match_count { 4 }
end
after(:create) do |stage, evaluator|
# match_count -1 automatically generates 2 ^ stage.level matches
# (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 }
end
end