From 7afb5ae552f9817bca82af79efda4eeddba01527 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 9 May 2019 16:21:49 +0200 Subject: [PATCH] Create realistic number of Matches When match_count is -1 the number of matches generated is automatically 2 ^ stage.level -> This is the amount of stages present in a "real" tournament stage. When supplying a positive number, it generates that many matches like before. This also now adds the position to the match list after creating them --- spec/factories/stages.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/factories/stages.rb b/spec/factories/stages.rb index e8dce2d..168acb6 100644 --- a/spec/factories/stages.rb +++ b/spec/factories/stages.rb @@ -19,7 +19,10 @@ FactoryBot.define do match_count { 4 } end after(:create) do |stage, evaluator| - stage.matches = create_list(:match, evaluator.match_count) + # 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.each_with_index { |match, i| match.position = i } end end end