This commit is contained in:
Daniel Schädler 2025-03-08 16:15:19 +01:00
parent 04143b2d2f
commit 755e15ec8a
4 changed files with 41 additions and 11 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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