Merge pull request #37 from turniere/ticket/TURNIERE-196
Factory Overhaul
This commit is contained in:
commit
0c9c0bd526
|
|
@ -4,5 +4,5 @@ class MatchScore < ApplicationRecord
|
||||||
belongs_to :match
|
belongs_to :match
|
||||||
belongs_to :team
|
belongs_to :team
|
||||||
|
|
||||||
delegate :owner, to: :team
|
delegate :owner, to: :match
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ RSpec.describe StatisticsController, type: :controller do
|
||||||
|
|
||||||
context 'tournament with a group stage' do
|
context 'tournament with a group stage' do
|
||||||
before do
|
before do
|
||||||
@tournament = create(:group_stage_tournament)
|
@tournament = create(:group_stage_only_tournament)
|
||||||
@group_stage = @tournament.stages.find_by(level: -1)
|
@group_stage = @tournament.stages.find_by(level: -1)
|
||||||
@most_dominant_score = create(:group_score,
|
@most_dominant_score = create(:group_score,
|
||||||
team: @tournament.teams.first,
|
team: @tournament.teams.first,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe TeamsController, type: :controller do
|
RSpec.describe TeamsController, type: :controller do
|
||||||
before do
|
before do
|
||||||
@team = create(:team)
|
@team = create(:tournament).teams.first
|
||||||
@owner = @team.owner
|
@owner = @team.owner
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
@user = @tournament.owner
|
@user = @tournament.owner
|
||||||
@another_user = create(:user)
|
@another_user = create(:user)
|
||||||
@private_tournament = create(:tournament, user: @another_user, public: false)
|
@private_tournament = create(:tournament, user: @another_user, public: false)
|
||||||
@teams = create_list(:detached_team, 4)
|
@teams = create_list(:team, 4)
|
||||||
@teams16 = create_list(:detached_team, 16)
|
@teams16 = create_list(:team, 16)
|
||||||
@groups = create_list(:group, 4)
|
@groups = create_list(:group, 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :playoff_match, aliases: [:match], class: Match do
|
factory :playoff_match, aliases: [:match], class: Match do
|
||||||
stage
|
stage
|
||||||
|
position { 0 }
|
||||||
factory :running_playoff_match do
|
factory :running_playoff_match do
|
||||||
transient do
|
transient do
|
||||||
match_scores_count { 2 }
|
match_scores_count { 2 }
|
||||||
|
|
@ -10,12 +11,29 @@ FactoryBot.define do
|
||||||
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 { 3 }
|
state { :in_progress }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :empty_prepared_playoff_match do
|
||||||
|
state { :not_started }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :decided_playoff_match do
|
||||||
|
transient do
|
||||||
|
match_scores_count { 2 }
|
||||||
|
end
|
||||||
|
after(:create) do |match, evaluator|
|
||||||
|
match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: 37)
|
||||||
|
# random number generated by blapplications
|
||||||
|
match.match_scores.first.points += 1
|
||||||
|
end
|
||||||
|
state { :team1_won }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :group_match, class: Match do
|
factory :group_match, class: Match do
|
||||||
group
|
group
|
||||||
|
position { 0 }
|
||||||
factory :running_group_match do
|
factory :running_group_match do
|
||||||
transient do
|
transient do
|
||||||
match_scores_count { 2 }
|
match_scores_count { 2 }
|
||||||
|
|
@ -23,7 +41,17 @@ FactoryBot.define do
|
||||||
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 { 3 }
|
state { :in_progress }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :undecided_group_match do
|
||||||
|
transient do
|
||||||
|
match_scores_count { 2 }
|
||||||
|
end
|
||||||
|
after(:create) do |match, evaluator|
|
||||||
|
match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: 3)
|
||||||
|
end
|
||||||
|
state { :team1_won }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,18 @@ FactoryBot.define do
|
||||||
factory :playoff_stage do
|
factory :playoff_stage do
|
||||||
level { rand(10) }
|
level { rand(10) }
|
||||||
transient do
|
transient do
|
||||||
|
match_type { :running_playoff_match }
|
||||||
match_count { 4 }
|
match_count { 4 }
|
||||||
end
|
end
|
||||||
after(:create) do |stage, evaluator|
|
after(:create) do |stage, evaluator|
|
||||||
stage.matches = create_list(:match, evaluator.match_count)
|
# match_count -1 automatically generates 2 ^ stage.level matches
|
||||||
|
# (as this would be the amount of stages present in the real world)
|
||||||
|
stage.matches = create_list(evaluator.match_type,
|
||||||
|
evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count)
|
||||||
|
stage.matches.each_with_index do |match, i|
|
||||||
|
match.position = i
|
||||||
|
end
|
||||||
|
stage.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,5 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :team do
|
factory :team do
|
||||||
name { Faker::Creature::Dog.name }
|
name { Faker::Creature::Dog.name }
|
||||||
tournament
|
|
||||||
end
|
|
||||||
|
|
||||||
factory :detached_team, class: Team do
|
|
||||||
name { Faker::Creature::Dog.name }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,55 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :tournament do
|
factory :tournament, aliases: [:stageless_tournament] do
|
||||||
name { Faker::Creature::Dog.name }
|
name { Faker::Creature::Dog.name }
|
||||||
description { Faker::Lorem.sentence }
|
description { Faker::Lorem.sentence }
|
||||||
user
|
user
|
||||||
transient do
|
transient do
|
||||||
teams_count { 16 }
|
teams_count { 8 }
|
||||||
end
|
end
|
||||||
after(:create) do |tournament, evaluator|
|
after(:create) do |tournament, evaluator|
|
||||||
tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament)
|
tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :group_stage_only_tournament do
|
||||||
|
transient do
|
||||||
|
group_count { 2 }
|
||||||
|
end
|
||||||
|
after(:create) do |tournament, evaluator|
|
||||||
|
tournament.stages << create(:group_stage, group_count: evaluator.group_count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
factory :stage_tournament do
|
factory :stage_tournament do
|
||||||
transient do
|
transient do
|
||||||
stage_count { 1 }
|
stage_count { 1 }
|
||||||
end
|
end
|
||||||
after(:create) do |tournament, evaluator|
|
after(:create) do |tournament, evaluator|
|
||||||
tournament.stages = create_list(:stage, evaluator.stage_count)
|
# this is basically a manual create_list as we need to count up the level of the stage
|
||||||
|
(1..evaluator.stage_count).each do |level|
|
||||||
|
tournament.stages << create(
|
||||||
|
:playoff_stage,
|
||||||
|
level: level,
|
||||||
|
match_count: -1,
|
||||||
|
match_type: evaluator.stage_count ? :running_playoff_match : :empty_prepared_playoff_match
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :group_stage_tournament do
|
||||||
|
after(:create) do |tournament, _evaluator|
|
||||||
|
tournament.stages << create(:group_stage)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :group_stage_tournament do
|
factory :dummy_stage_tournament do
|
||||||
after(:create) do |tournament, _evaluator|
|
transient do
|
||||||
tournament.stages = create_list(:group_stage, 1)
|
stage_count { 3 }
|
||||||
|
end
|
||||||
|
after(:create) do |tournament, evaluator|
|
||||||
|
tournament.stages.concat create_list(:stage, evaluator.stage_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue