From 755e15ec8a1304d2ae4d941eeac6da1101cd4abe Mon Sep 17 00:00:00 2001 From: Malaber Date: Sat, 8 Mar 2025 16:15:19 +0100 Subject: [PATCH] WIP --- spec/factories/groups.rb | 1 - spec/factories/stages.rb | 5 +++++ spec/factories/tournaments.rb | 16 ++++++---------- spec/models/tournament_spec.rb | 30 ++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index ba375c5..abe994f 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -8,7 +8,6 @@ FactoryBot.define do end sequence(:number) - stage after(:create) do |group, evaluator| create_list(evaluator.match_factory, evaluator.match_count, group: group) diff --git a/spec/factories/stages.rb b/spec/factories/stages.rb index 992eee1..7f06201 100644 --- a/spec/factories/stages.rb +++ b/spec/factories/stages.rb @@ -13,6 +13,8 @@ FactoryBot.define do end after(:create) do |stage, evaluator| stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory) + stage.tournament.stages << stage + stage.save! end end @@ -28,6 +30,7 @@ FactoryBot.define do stage.matches.each_with_index do |match, i| match.position = i end + stage.tournament.stages << stage stage.save! end end @@ -41,6 +44,8 @@ FactoryBot.define do end after(:create) do |stage, evaluator| stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory) + stage.tournament.stages << stage + stage.save! end end end diff --git a/spec/factories/tournaments.rb b/spec/factories/tournaments.rb index 56746e5..90aa8ab 100644 --- a/spec/factories/tournaments.rb +++ b/spec/factories/tournaments.rb @@ -42,7 +42,6 @@ FactoryBot.define do factory :group_stage_tournament do transient do group_count { 2 } - match_factory { :group_match } end after(:create) do |tournament, evaluator| tournament.stages << create(:group_stage, @@ -61,19 +60,16 @@ FactoryBot.define do end end - factory :beerpong_tournament, parent: :tournament do + factory :bpwstr_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 + playoff_teams_amount { 16 } + after(:create) do |tournament| + group_stage = + tournament.stages << group_stage + tournament.teams = stages.first.groups.map(&:teams).flatten tournament.save! end end diff --git a/spec/models/tournament_spec.rb b/spec/models/tournament_spec.rb index a555abe..1a381c7 100644 --- a/spec/models/tournament_spec.rb +++ b/spec/models/tournament_spec.rb @@ -56,4 +56,34 @@ RSpec.describe Tournament, type: :model do end end end + + describe 'Factory', focus: true do + it 'creates a valid tournament' do + tournament = create(:tournament) + expect(tournament).to be_valid + end + + it 'creates a valid stage tournament' do + tournament = create(:stage_tournament) + expect(tournament).to be_valid + end + + it 'creates a valid group stage tournament' do + tournament = create(:group_stage_tournament) + expect(tournament).to be_valid + end + describe 'bpwstr tournament' do + it 'creates a valid bpwstr tournament' do + tournament = create(:bpwstr_tournament) + expect(tournament).to be_valid + end + + it 'has the correct teams assigned to it' do + tournament = create(:bpwstr_tournament) + expect(tournament.teams.count).to eq(32) + # also check that the teams in the matches are the same + expect(tournament.teams).to match_array(tournament.matches.map(&:teams).flatten) + end + end + end end