Make Match Factory configurable for group_stage and group factory

This commit is contained in:
Daniel Schädler 2019-05-30 00:04:47 +02:00
parent c674e5fcab
commit 5925f23720
3 changed files with 10 additions and 4 deletions

View File

@ -4,13 +4,14 @@ FactoryBot.define do
factory :group do
transient do
match_count { 4 }
match_factory { :group_match }
end
sequence(:number)
stage
after(:create) do |group, evaluator|
create_list(:group_match, evaluator.match_count, group: group)
create_list(evaluator.match_factory, evaluator.match_count, group: group)
group.group_scores = group.teams.map do |team|
create(:group_score, team: team, group: group)
end

View File

@ -34,14 +34,18 @@ FactoryBot.define do
factory :group_match, class: Match do
group
position { 0 }
factory :running_group_match do
factory :filled_group_match do
transient do
match_scores_count { 2 }
end
factory :running_group_match do
state { :in_progress }
end
after(:create) do |match, evaluator|
match.match_scores = create_list(:match_score, evaluator.match_scores_count)
end
state { :in_progress }
end
factory :undecided_group_match do

View File

@ -7,9 +7,10 @@ FactoryBot.define do
level { -1 }
transient do
group_count { 4 }
match_factory { :group_match }
end
after(:create) do |stage, evaluator|
stage.groups = create_list(:group, evaluator.group_count)
stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory)
end
end