mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
Protect tournament from out of order seeding.
This commit is contained in:
@@ -205,25 +205,38 @@ class Tournament < ApplicationRecord
|
|||||||
return error_string
|
return error_string
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_generation_error
|
def wrestlers_with_out_of_order_seed_error
|
||||||
error_string = ""
|
error_string = ""
|
||||||
if pool_to_bracket_number_of_wrestlers_error.length > 0
|
weights.each do |weight|
|
||||||
error_string += pool_to_bracket_number_of_wrestlers_error
|
original_seeds = weight.wrestlers.map(&:original_seed).compact.sort
|
||||||
elsif modified_sixteen_man_number_of_wrestlers_error.length > 0
|
if original_seeds.any? && original_seeds != (original_seeds.first..original_seeds.last).to_a
|
||||||
error_string += modified_sixteen_man_number_of_wrestlers_error
|
error_string += "The weight class #{weight.max} has wrestlers with out-of-order seeds: #{original_seeds}. There is a gap in the sequence."
|
||||||
elsif double_elim_number_of_wrestlers_error.length > 0
|
end
|
||||||
error_string += double_elim_number_of_wrestlers_error
|
end
|
||||||
|
return error_string
|
||||||
|
end
|
||||||
|
|
||||||
|
def match_generation_error
|
||||||
|
error_string = ""
|
||||||
|
if pool_to_bracket_number_of_wrestlers_error.length > 0
|
||||||
|
error_string += pool_to_bracket_number_of_wrestlers_error
|
||||||
|
elsif modified_sixteen_man_number_of_wrestlers_error.length > 0
|
||||||
|
error_string += modified_sixteen_man_number_of_wrestlers_error
|
||||||
|
elsif double_elim_number_of_wrestlers_error.length > 0
|
||||||
|
error_string += double_elim_number_of_wrestlers_error
|
||||||
elsif wrestlers_with_higher_seed_than_bracket_size_error.length > 0
|
elsif wrestlers_with_higher_seed_than_bracket_size_error.length > 0
|
||||||
error_string += wrestlers_with_higher_seed_than_bracket_size_error
|
error_string += wrestlers_with_higher_seed_than_bracket_size_error
|
||||||
elsif wrestlers_with_duplicate_original_seed_error.length > 0
|
elsif wrestlers_with_duplicate_original_seed_error.length > 0
|
||||||
error_string += wrestlers_with_duplicate_original_seed_error
|
error_string += wrestlers_with_duplicate_original_seed_error
|
||||||
end
|
elsif wrestlers_with_out_of_order_seed_error.length > 0
|
||||||
|
error_string += wrestlers_with_out_of_order_seed_error
|
||||||
|
end
|
||||||
if error_string.length > 0
|
if error_string.length > 0
|
||||||
return "There is a tournament error. #{error_string}"
|
return "There is a tournament error. #{error_string}"
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_and_fill_bout_board
|
def reset_and_fill_bout_board
|
||||||
reset_mats
|
reset_mats
|
||||||
|
|||||||
@@ -760,4 +760,44 @@ class TournamentsControllerTest < ActionController::TestCase
|
|||||||
get :generate_matches, params: { id: @tournament.id }
|
get :generate_matches, params: { id: @tournament.id }
|
||||||
redirect_tournament_error
|
redirect_tournament_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "tournament generation error when a weight class has wrestlers with out-of-order original seeds" do
|
||||||
|
sign_in_owner
|
||||||
|
create_pool_tournament_single_weight(5) # Create a weight class with 5 wrestlers
|
||||||
|
@tournament.destroy_all_matches
|
||||||
|
@tournament.user_id = 1
|
||||||
|
@tournament.save
|
||||||
|
|
||||||
|
# Set seeds to have a gap: [1, 2, 3, 5, nil]
|
||||||
|
wrestlers = @tournament.weights.first.wrestlers
|
||||||
|
wrestlers[0].original_seed = 1
|
||||||
|
wrestlers[1].original_seed = 2
|
||||||
|
wrestlers[2].original_seed = 3
|
||||||
|
wrestlers[3].original_seed = 5
|
||||||
|
wrestlers[4].original_seed = nil # Unseeded wrestler
|
||||||
|
wrestlers.each(&:save)
|
||||||
|
|
||||||
|
get :generate_matches, params: { id: @tournament.id }
|
||||||
|
redirect_tournament_error
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament owner can generate matches with the correct seed order" do
|
||||||
|
sign_in_owner
|
||||||
|
create_pool_tournament_single_weight(5) # Create a weight class with 5 wrestlers
|
||||||
|
@tournament.destroy_all_matches
|
||||||
|
@tournament.user_id = 1
|
||||||
|
@tournament.save
|
||||||
|
|
||||||
|
# Set seeds to have a gap: [1, 2, 3, 5, nil]
|
||||||
|
wrestlers = @tournament.weights.first.wrestlers
|
||||||
|
wrestlers[0].original_seed = 1
|
||||||
|
wrestlers[1].original_seed = 2
|
||||||
|
wrestlers[2].original_seed = 3
|
||||||
|
wrestlers[3].original_seed = 4
|
||||||
|
wrestlers[4].original_seed = nil # Unseeded wrestler
|
||||||
|
wrestlers.each(&:save)
|
||||||
|
|
||||||
|
get :generate_matches, params: { id: @tournament.id }
|
||||||
|
success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user