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 133cbffc71
commit 8a95f24211
3 changed files with 10 additions and 4 deletions

View File

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

View File

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

View File

@ -7,9 +7,10 @@ FactoryBot.define do
level { -1 } level { -1 }
transient do transient do
group_count { 4 } group_count { 4 }
match_factory { :group_match }
end end
after(:create) do |stage, evaluator| 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
end end