WIP
This commit is contained in:
parent
04143b2d2f
commit
755e15ec8a
|
|
@ -8,7 +8,6 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
sequence(:number)
|
sequence(:number)
|
||||||
stage
|
|
||||||
|
|
||||||
after(:create) do |group, evaluator|
|
after(:create) do |group, evaluator|
|
||||||
create_list(evaluator.match_factory, evaluator.match_count, group: group)
|
create_list(evaluator.match_factory, evaluator.match_count, group: group)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
after(:create) do |stage, evaluator|
|
after(:create) do |stage, evaluator|
|
||||||
stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory)
|
stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory)
|
||||||
|
stage.tournament.stages << stage
|
||||||
|
stage.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -28,6 +30,7 @@ FactoryBot.define do
|
||||||
stage.matches.each_with_index do |match, i|
|
stage.matches.each_with_index do |match, i|
|
||||||
match.position = i
|
match.position = i
|
||||||
end
|
end
|
||||||
|
stage.tournament.stages << stage
|
||||||
stage.save!
|
stage.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -41,6 +44,8 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
after(:create) do |stage, evaluator|
|
after(:create) do |stage, evaluator|
|
||||||
stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory)
|
stage.groups = create_list(:group, evaluator.group_count, match_factory: evaluator.match_factory)
|
||||||
|
stage.tournament.stages << stage
|
||||||
|
stage.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ FactoryBot.define do
|
||||||
factory :group_stage_tournament do
|
factory :group_stage_tournament do
|
||||||
transient do
|
transient do
|
||||||
group_count { 2 }
|
group_count { 2 }
|
||||||
match_factory { :group_match }
|
|
||||||
end
|
end
|
||||||
after(:create) do |tournament, evaluator|
|
after(:create) do |tournament, evaluator|
|
||||||
tournament.stages << create(:group_stage,
|
tournament.stages << create(:group_stage,
|
||||||
|
|
@ -61,19 +60,16 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :beerpong_tournament, parent: :tournament do
|
factory :bpwstr_tournament do
|
||||||
transient do
|
transient do
|
||||||
teams_count { 32 }
|
teams_count { 32 }
|
||||||
group_count { 8 }
|
group_count { 8 }
|
||||||
match_factory { :group_match }
|
|
||||||
end
|
end
|
||||||
|
playoff_teams_amount { 16 }
|
||||||
after(:create) do |tournament, evaluator|
|
after(:create) do |tournament|
|
||||||
tournament.stages << create(:group_stage,
|
group_stage =
|
||||||
match_factory: evaluator.match_factory,
|
tournament.stages << group_stage
|
||||||
group_count: evaluator.group_count)
|
tournament.teams = stages.first.groups.map(&:teams).flatten
|
||||||
tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament)
|
|
||||||
tournament.playoff_teams_amount = 16
|
|
||||||
tournament.save!
|
tournament.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,34 @@ RSpec.describe Tournament, type: :model do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue