mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added a tournament error if more than 1 person in a weight has the same seed.
This commit is contained in:
@@ -192,6 +192,18 @@ class Tournament < ApplicationRecord
|
|||||||
end
|
end
|
||||||
return error_string
|
return error_string
|
||||||
end
|
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
|
def match_generation_error
|
||||||
error_string = ""
|
error_string = ""
|
||||||
@@ -203,6 +215,8 @@ class Tournament < ApplicationRecord
|
|||||||
error_string += double_elim_number_of_wrestlers_error
|
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
|
||||||
|
error_string += wrestlers_with_duplicate_original_seed_error
|
||||||
end
|
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}"
|
||||||
|
|||||||
@@ -747,4 +747,17 @@ 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 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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user