From 275847befedb972d7dc313c8592a7a8c72190ae7 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 7 Jan 2025 16:00:17 -0500 Subject: [PATCH] Added a tournament error if more than 1 person in a weight has the same seed. --- app/models/tournament.rb | 14 ++++++++++++++ test/controllers/tournaments_controller_test.rb | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 119fcca..c2d9d66 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -192,6 +192,18 @@ class Tournament < ApplicationRecord end return error_string end + + def wrestlers_with_duplicate_original_seed_error + error_string = "" + weights.each do |weight| + weight.wrestlers.select{|wr| wr.original_seed != nil}.each do |wrestler| + if weight.wrestlers.select{|wr| wr.original_seed == wrestler.original_seed}.size > 1 + error_string += "More than 1 wrestler in the #{weight.max} weight class is seeded #{wrestler.original_seed}." + end + end + end + return error_string + end def match_generation_error error_string = "" @@ -203,6 +215,8 @@ class Tournament < ApplicationRecord error_string += double_elim_number_of_wrestlers_error elsif wrestlers_with_higher_seed_than_bracket_size_error.length > 0 error_string += wrestlers_with_higher_seed_than_bracket_size_error + elsif wrestlers_with_duplicate_original_seed_error.length > 0 + error_string += wrestlers_with_duplicate_original_seed_error end if error_string.length > 0 return "There is a tournament error. #{error_string}" diff --git a/test/controllers/tournaments_controller_test.rb b/test/controllers/tournaments_controller_test.rb index 89debae..5d58923 100644 --- a/test/controllers/tournaments_controller_test.rb +++ b/test/controllers/tournaments_controller_test.rb @@ -747,4 +747,17 @@ class TournamentsControllerTest < ActionController::TestCase get :generate_matches, params: { id: @tournament.id } redirect_tournament_error end + + test "tournament generation error when two wrestlers in a weight class have the same original_seed" do + sign_in_owner + create_pool_tournament_single_weight(5) + @tournament.destroy_all_matches + @tournament.user_id = 1 + @tournament.save + wrestler = @tournament.weights.first.wrestlers.second + wrestler.original_seed = 1 + wrestler.save + get :generate_matches, params: { id: @tournament.id } + redirect_tournament_error + end end