diff --git a/spec/factories/matches.rb b/spec/factories/matches.rb index 6b9facd..fecade1 100644 --- a/spec/factories/matches.rb +++ b/spec/factories/matches.rb @@ -4,14 +4,18 @@ FactoryBot.define do factory :playoff_match, aliases: [:match], class: Match do stage position { 0 } + factory :running_playoff_match do transient do match_scores_count { 2 } end + after(:create) do |match, evaluator| match.match_scores = create_list(:match_score, evaluator.match_scores_count) end + state { :in_progress } + factory :finished_playoff_match do state { :finished } end @@ -32,11 +36,13 @@ FactoryBot.define do transient do match_scores_count { 2 } end + after(:create) do |match, evaluator| match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: 37) # random number generated by blapplications match.match_scores.first.points += 1 end + state { :finished } end end @@ -44,6 +50,7 @@ FactoryBot.define do factory :group_match, class: Match do group position { 0 } + factory :filled_group_match do transient do match_scores_count { 2 } @@ -66,10 +73,25 @@ FactoryBot.define do transient do match_scores_count { 2 } end + after(:create) do |match, evaluator| match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: 3) end + + state { :finished } + end + + factory :decided_group_match do + transient do + match_scores_count { 2 } + end + + after(:create) do |match, evaluator| + match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: 37) + match.match_scores.first.points += 1 + end + state { :finished } end end -end +end \ No newline at end of file diff --git a/spec/factories/stages.rb b/spec/factories/stages.rb index 8027cd7..992eee1 100644 --- a/spec/factories/stages.rb +++ b/spec/factories/stages.rb @@ -3,6 +3,7 @@ FactoryBot.define do factory :stage do tournament + factory :group_stage do level { -1 } state { :in_progress } @@ -22,8 +23,6 @@ FactoryBot.define do 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(evaluator.match_type, evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count) stage.matches.each_with_index do |match, i| @@ -32,5 +31,17 @@ FactoryBot.define do stage.save! end end + + factory :decided_group_stage do + level { -1 } + state { :finished } + transient do + group_count { 8 } + match_factory { :decided_group_match } + end + after(:create) do |stage, evaluator| + stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory) + end + end end -end +end \ No newline at end of file diff --git a/spec/factories/tournaments.rb b/spec/factories/tournaments.rb index 9a8a7d3..56746e5 100644 --- a/spec/factories/tournaments.rb +++ b/spec/factories/tournaments.rb @@ -60,5 +60,22 @@ FactoryBot.define do tournament.stages.concat create_list(:stage, evaluator.stage_count) end end + + factory :beerpong_tournament, parent: :tournament do + transient do + teams_count { 32 } + group_count { 8 } + match_factory { :group_match } + end + + after(:create) do |tournament, evaluator| + tournament.stages << create(:group_stage, + match_factory: evaluator.match_factory, + group_count: evaluator.group_count) + tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament) + tournament.playoff_teams_amount = 16 + tournament.save! + end + end end end