Makes match_type configurable instead of only setting its state
This commit is contained in:
parent
b9afa956ce
commit
80b14900d0
|
|
@ -16,15 +16,14 @@ 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_type { :running_playoff_match }
|
||||||
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(:running_playoff_match,
|
stage.matches = create_list(evaluator.match_type,
|
||||||
evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count,
|
evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count)
|
||||||
state: evaluator.match_state)
|
|
||||||
stage.matches.each_with_index do |match, i|
|
stage.matches.each_with_index do |match, i|
|
||||||
match.position = i
|
match.position = i
|
||||||
match.save
|
match.save
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,17 @@ FactoryBot.define do
|
||||||
after(:create) do |tournament, evaluator|
|
after(:create) do |tournament, evaluator|
|
||||||
# this is basically a manual create_list as we need to count up the level of the stage
|
# this is basically a manual create_list as we need to count up the level of the stage
|
||||||
levels = 1..evaluator.stage_count
|
levels = 1..evaluator.stage_count
|
||||||
tournament.stages.concat levels
|
|
||||||
.map { |level|
|
tournament.stages.concat(levels.map do |level|
|
||||||
create(:playoff_stage,
|
create(:playoff_stage,
|
||||||
level: level,
|
level: level,
|
||||||
match_count: -1,
|
match_count: -1,
|
||||||
match_state: level == evaluator.stage_count ? :in_progress : :not_started)
|
match_type: if evaluator.stage_count
|
||||||
}
|
:running_playoff_match
|
||||||
|
else
|
||||||
|
:empty_prepared_playoff_match
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :group_stage_tournament do
|
factory :group_stage_tournament do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue