mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
Added queues for mats and provided a way for tournament directors to move matches to a mat.
This commit is contained in:
@@ -25,6 +25,7 @@ class MatchesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
def post_update_from_match_stat
|
||||
@request.env["HTTP_REFERER"] = "/tournaments/#{@tournament.id}/matches"
|
||||
get :stat, params: { id: @match.id }
|
||||
patch :update, params: { id: @match.id, match: {tournament_id: 1, mat_id: 1} }
|
||||
end
|
||||
@@ -32,6 +33,21 @@ class MatchesControllerTest < ActionController::TestCase
|
||||
def get_stat
|
||||
get :stat, params: { id: @match.id }
|
||||
end
|
||||
|
||||
def get_edit_assignment(extra_params = {})
|
||||
get :edit_assignment, params: { id: @match.id }.merge(extra_params)
|
||||
end
|
||||
|
||||
def patch_update_assignment(extra_params = {})
|
||||
base = {
|
||||
id: @match.id,
|
||||
match: {
|
||||
mat_id: @match.mat_id,
|
||||
queue_position: 2
|
||||
}
|
||||
}
|
||||
patch :update_assignment, params: base.deep_merge(extra_params)
|
||||
end
|
||||
|
||||
def sign_in_owner
|
||||
sign_in users(:one)
|
||||
@@ -174,4 +190,72 @@ class MatchesControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
assert_includes @response.body, time_ago_in_words(finished_at), "time_ago_in_words(finished_at) should be displayed on the page"
|
||||
end
|
||||
|
||||
test "tournament owner can view edit_assignment and execute update_assignment" do
|
||||
sign_in_owner
|
||||
get_edit_assignment
|
||||
assert_response :success
|
||||
|
||||
patch_update_assignment
|
||||
assert_response :redirect
|
||||
assert_not_equal "/static_pages/not_allowed", @response.redirect_url&.sub("http://test.host", "")
|
||||
end
|
||||
|
||||
test "tournament delegate can view edit_assignment and execute update_assignment" do
|
||||
sign_in_tournament_delegate
|
||||
get_edit_assignment
|
||||
assert_response :success
|
||||
|
||||
patch_update_assignment
|
||||
assert_response :redirect
|
||||
assert_not_equal "/static_pages/not_allowed", @response.redirect_url&.sub("http://test.host", "")
|
||||
end
|
||||
|
||||
test "school delegate cannot view edit_assignment or execute update_assignment" do
|
||||
sign_in_school_delegate
|
||||
get_edit_assignment
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
patch_update_assignment
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
end
|
||||
|
||||
test "non logged in user cannot view edit_assignment or execute update_assignment" do
|
||||
get_edit_assignment
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
patch_update_assignment
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
end
|
||||
|
||||
test "logged in user without delegations cannot view edit_assignment or execute update_assignment" do
|
||||
sign_in_non_owner
|
||||
get_edit_assignment
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
patch_update_assignment
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
end
|
||||
|
||||
test "valid school permission key cannot view edit_assignment or execute update_assignment" do
|
||||
school = @tournament.schools.first
|
||||
school.update!(permission_key: "valid-school-key")
|
||||
|
||||
get_edit_assignment(school_permission_key: "valid-school-key")
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
patch_update_assignment(school_permission_key: "valid-school-key")
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
end
|
||||
|
||||
test "invalid school permission key cannot view edit_assignment or execute update_assignment" do
|
||||
school = @tournament.schools.first
|
||||
school.update!(permission_key: "valid-school-key")
|
||||
|
||||
get_edit_assignment(school_permission_key: "invalid-school-key")
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
patch_update_assignment(school_permission_key: "invalid-school-key")
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,10 @@ class MatsControllerTest < ActionController::TestCase
|
||||
# @tournament.generateMatchups
|
||||
@match = Match.where("tournament_id = ? and mat_id = ?",1,1).first
|
||||
@mat = mats(:one)
|
||||
@match ||= @tournament.matches.first
|
||||
if @match && @mat.queue1.nil?
|
||||
@mat.assign_match_to_queue!(@match, 1)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -242,7 +246,7 @@ class MatsControllerTest < ActionController::TestCase
|
||||
test "logged in tournament owner should redirect back to the first unfinished bout on a mat after submitting a match with a bout number param" do
|
||||
sign_in_owner
|
||||
|
||||
first_bout_number = @mat.unfinished_matches.first.bout_number
|
||||
first_bout_number = @mat.queue1_match.bout_number
|
||||
|
||||
# Set a specific bout number to test
|
||||
bout_number = @match.bout_number
|
||||
|
||||
289
test/integration/bout_board_test.rb
Normal file
289
test/integration/bout_board_test.rb
Normal file
@@ -0,0 +1,289 @@
|
||||
require "test_helper"
|
||||
|
||||
class BoutBoardTest < ActionDispatch::IntegrationTest
|
||||
test "only assigns matches with w1 and w2" do
|
||||
create_double_elim_tournament_single_weight(16, "Regular Double Elimination 1-6")
|
||||
mat = @tournament.mats.create!(name: "Mat 1")
|
||||
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
@tournament.matches.update_all(w1: nil)
|
||||
|
||||
@tournament.reset_and_fill_bout_board
|
||||
mat.reload
|
||||
|
||||
assert_empty mat.queue_match_ids.compact, "No matches should be assigned when w1 is missing"
|
||||
|
||||
GenerateTournamentMatches.new(@tournament).generate
|
||||
@tournament.reload
|
||||
@tournament.matches.reload
|
||||
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
@tournament.matches.update_all(w2: nil)
|
||||
|
||||
@tournament.reset_and_fill_bout_board
|
||||
mat.reload
|
||||
|
||||
assert_empty mat.queue_match_ids.compact, "No matches should be assigned when w2 is missing"
|
||||
end
|
||||
|
||||
test "only assigns matches without a loser1_name or loser2_name of BYE" do
|
||||
create_double_elim_tournament_single_weight(16, "Regular Double Elimination 1-6")
|
||||
mat = @tournament.mats.create!(name: "Mat 1")
|
||||
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
@tournament.matches.update_all(loser1_name: "BYE")
|
||||
|
||||
@tournament.reset_and_fill_bout_board
|
||||
mat.reload
|
||||
|
||||
assert_empty mat.queue_match_ids.compact, "No matches should be assigned when loser1_name is BYE"
|
||||
|
||||
GenerateTournamentMatches.new(@tournament).generate
|
||||
@tournament.reload
|
||||
@tournament.matches.reload
|
||||
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
@tournament.matches.update_all(loser2_name: "BYE")
|
||||
|
||||
@tournament.reset_and_fill_bout_board
|
||||
mat.reload
|
||||
|
||||
assert_empty mat.queue_match_ids.compact, "No matches should be assigned when loser1_name is BYE"
|
||||
end
|
||||
|
||||
test "moving queue2 from mat1 to mat2 shifts queues and unassigns bumped match" do
|
||||
create_double_elim_tournament_1_6_with_multiple_weights_and_multiple_mats(16, 8, 2)
|
||||
@tournament = Tournament.find(@tournament.id)
|
||||
|
||||
eligible_matches = Match.where(tournament_id: @tournament.id)
|
||||
.where(finished: [nil, 0])
|
||||
.where.not(bout_number: nil)
|
||||
.where.not(w1: nil)
|
||||
.where.not(w2: nil)
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
.where(mat_id: nil)
|
||||
assert eligible_matches.count >= 8, "Expected enough eligible matches to fill two mats"
|
||||
|
||||
@tournament.reload
|
||||
@tournament.matches.reload
|
||||
@tournament.reset_and_fill_bout_board
|
||||
@tournament = Tournament.find(@tournament.id)
|
||||
mat1 = @tournament.mats.order(:id).first
|
||||
mat2 = @tournament.mats.order(:id).second
|
||||
mat1.reload
|
||||
mat2.reload
|
||||
|
||||
assert mat1.queue2_match, "Expected mat1 queue2 to be assigned"
|
||||
assert mat1.queue3_match, "Expected mat1 queue3 to be assigned"
|
||||
assert mat1.queue4_match, "Expected mat1 queue4 to be assigned"
|
||||
assert mat2.queue2_match, "Expected mat2 queue2 to be assigned"
|
||||
assert mat2.queue3_match, "Expected mat2 queue3 to be assigned"
|
||||
assert mat2.queue4_match, "Expected mat2 queue4 to be assigned"
|
||||
|
||||
mat1_q2 = mat1.queue2_match
|
||||
mat1_q3 = mat1.queue3_match
|
||||
mat1_q4 = mat1.queue4_match
|
||||
|
||||
mat2_q2 = mat2.queue2_match
|
||||
mat2_q3 = mat2.queue3_match
|
||||
mat2_q4 = mat2.queue4_match
|
||||
|
||||
mat2_q4_original_match = Match.find(mat2_q4.id)
|
||||
|
||||
mat2.assign_match_to_queue!(mat1_q2, 2)
|
||||
|
||||
mat1.reload
|
||||
mat2.reload
|
||||
|
||||
assert_equal mat1_q2.id, mat2.queue2, "Moved match should land in mat2 queue2"
|
||||
assert_equal mat2_q2.id, mat2.queue3, "Mat2 queue2 should shift to queue3"
|
||||
assert_equal mat2_q3.id, mat2.queue4, "Mat2 queue3 should shift to queue4"
|
||||
assert_nil mat2_q4.reload.mat_id, "Original mat2 queue4 match should be unassigned"
|
||||
|
||||
assert_equal mat1_q3.id, mat1.queue2, "Mat1 queue3 should shift to queue2"
|
||||
assert_equal mat1_q4.id, mat1.queue3, "Mat1 queue4 should shift to queue3"
|
||||
assert mat1.queue4, "Mat1 queue4 should be refilled"
|
||||
refute_includes [mat1_q2.id, mat1_q3.id, mat1_q4.id], mat1.queue4, "Mat1 queue4 should be a new match"
|
||||
assert_equal mat1.id, Match.find(mat1.queue4).mat_id, "New mat1 queue4 match should be assigned to mat1"
|
||||
assert_nil mat2_q4_original_match.reload.mat_id, "Mat 2 queue4 match should no longer have a mat_id"
|
||||
end
|
||||
|
||||
test "moving queue2 to queue4 on the same mat shifts queues" do
|
||||
create_double_elim_tournament_1_6_with_multiple_weights_and_multiple_mats(16, 8, 1)
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat1 = @tournament.mats.order(:id).first
|
||||
mat1.reload
|
||||
|
||||
assert mat1.queue2_match, "Expected mat1 queue2 to be assigned"
|
||||
assert mat1.queue3_match, "Expected mat1 queue3 to be assigned"
|
||||
assert mat1.queue4_match, "Expected mat1 queue4 to be assigned"
|
||||
|
||||
mat1_q2 = mat1.queue2_match
|
||||
mat1_q3 = mat1.queue3_match
|
||||
mat1_q4 = mat1.queue4_match
|
||||
|
||||
mat1.assign_match_to_queue!(mat1_q2, 4)
|
||||
mat1.reload
|
||||
|
||||
assert_equal mat1_q3.id, mat1.queue2, "Mat1 queue3 should shift to queue2"
|
||||
assert_equal mat1_q4.id, mat1.queue3, "Mat1 queue4 should shift to queue3"
|
||||
assert_equal mat1_q2.id, mat1.queue4, "Mat1 queue2 should move to queue4"
|
||||
end
|
||||
|
||||
test "moving queue4 to queue2 on the same mat shifts queues" do
|
||||
create_double_elim_tournament_1_6_with_multiple_weights_and_multiple_mats(16, 8, 1)
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat1 = @tournament.mats.order(:id).first
|
||||
mat1.reload
|
||||
|
||||
assert mat1.queue2_match, "Expected mat1 queue2 to be assigned"
|
||||
assert mat1.queue3_match, "Expected mat1 queue3 to be assigned"
|
||||
assert mat1.queue4_match, "Expected mat1 queue4 to be assigned"
|
||||
|
||||
mat1_q2 = mat1.queue2_match
|
||||
mat1_q3 = mat1.queue3_match
|
||||
mat1_q4 = mat1.queue4_match
|
||||
|
||||
mat1.assign_match_to_queue!(mat1_q4, 2)
|
||||
mat1.reload
|
||||
|
||||
assert_equal mat1_q4.id, mat1.queue2, "Mat1 queue4 should move to queue2"
|
||||
assert_equal mat1_q2.id, mat1.queue3, "Mat1 original queue2 should move to queue3"
|
||||
assert_equal mat1_q3.id, mat1.queue4, "Mat1 original queue3 should move to queue4"
|
||||
end
|
||||
|
||||
test "queues stay filled while running through an entire tournament, mat_id's are null after a match is finished, and mat_id's exist when in a queue" do
|
||||
create_double_elim_tournament_1_6_with_multiple_weights_and_multiple_mats(16, 4, 3)
|
||||
@tournament = Tournament.find(@tournament.id)
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
max_iterations = @tournament.matches.count + 20
|
||||
iterations = 0
|
||||
|
||||
loop do
|
||||
iterations += 1
|
||||
assert_operator iterations, :<=, max_iterations, "Loop exceeded expected match count"
|
||||
|
||||
assert_queue_depth_matches_available_bouts(@tournament)
|
||||
|
||||
next_match = next_queued_finishable_match(@tournament)
|
||||
break unless next_match
|
||||
|
||||
next_match.update!(
|
||||
winner_id: next_match.w1,
|
||||
win_type: "Decision",
|
||||
score: "1-0",
|
||||
finished: 1
|
||||
)
|
||||
|
||||
assert_nil next_match.reload.mat_id, "The match should have a null mat_id after it is finished"
|
||||
|
||||
@tournament.reload
|
||||
end
|
||||
|
||||
remaining_finishable = finishable_match_scope(@tournament).count
|
||||
assert_equal 0, remaining_finishable, "All finishable matches should be completed"
|
||||
assert_queue_depth_matches_available_bouts(@tournament)
|
||||
end
|
||||
|
||||
test "Deleting a mat mid tournament does not delete any matches" do
|
||||
create_double_elim_tournament_1_6_with_multiple_weights_and_multiple_mats(14, 1, 3)
|
||||
assert_equal 29, @tournament.matches.count, "Before deleting a mat total number of matches for a 14 man double elim 1-6 tournament should be 29"
|
||||
assert_equal 1, @tournament.matches.select{|m| m.bracket_position == "1/2"}.count, "Before deleting a mat there should be 1 match for bracket position 1/2"
|
||||
assert_equal 1, @tournament.matches.select{|m| m.bracket_position == "3/4"}.count, "Before deleting a mat there should be 1 match for bracket position 3/4"
|
||||
assert_equal 1, @tournament.matches.select{|m| m.bracket_position == "5/6"}.count, "Before deleting a mat there should be 1 match for bracket position 5/6"
|
||||
assert_equal 8, @tournament.matches.select{|m| m.bracket_position == "Bracket Round of 16"}.count, "Before deleting a mat there should be 8 matches for bracket position Bracket Round of 16"
|
||||
assert_equal 4, @tournament.matches.select{|m| m.bracket_position == "Conso Round of 8.1"}.count, "Before deleting a mat there should be 4 matches for bracket position Conso Round of 8.1"
|
||||
assert_equal 4, @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count, "Before deleting a mat there should be 4 matches for bracket position Quarter"
|
||||
assert_equal 2, @tournament.matches.select{|m| m.bracket_position == "Semis"}.count, "Before deleting a mat there should be 2 matches for bracket position Semis"
|
||||
assert_equal 4, @tournament.matches.select{|m| m.bracket_position == "Conso Round of 8.2"}.count, "Before deleting a mat there should be 4 matches for bracket position Conso Round of 8.2"
|
||||
assert_equal 2, @tournament.matches.select{|m| m.bracket_position == "Conso Quarter"}.count, "Before deleting a mat there should be 2 matches for bracket position Conso Quarter"
|
||||
assert_equal 2, @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.count, "Before deleting a mat there should be 2 matches for bracket position Conso Semis"
|
||||
|
||||
@tournament.mats.first.destroy
|
||||
@tournament.reload
|
||||
@tournament.matches.reload
|
||||
|
||||
assert_equal 29, @tournament.matches.count, "After deleting a mat total number of matches for a 14 man double elim 1-6 tournament should still be 29"
|
||||
assert_equal 1, @tournament.matches.select{|m| m.bracket_position == "1/2"}.count, "After deleting a mat there should still be 1 match for bracket position 1/2"
|
||||
assert_equal 1, @tournament.matches.select{|m| m.bracket_position == "3/4"}.count, "After deleting a mat there should still be 1 match for bracket position 3/4"
|
||||
assert_equal 1, @tournament.matches.select{|m| m.bracket_position == "5/6"}.count, "After deleting a mat there should still be 1 match for bracket position 5/6"
|
||||
assert_equal 8, @tournament.matches.select{|m| m.bracket_position == "Bracket Round of 16"}.count, "After deleting a mat there should still be 8 matches for bracket position Bracket Round of 16"
|
||||
assert_equal 4, @tournament.matches.select{|m| m.bracket_position == "Conso Round of 8.1"}.count, "After deleting a mat there should still be 4 matches for bracket position Conso Round of 8.1"
|
||||
assert_equal 4, @tournament.matches.select{|m| m.bracket_position == "Quarter"}.count, "After deleting a mat there should still be 4 matches for bracket position Quarter"
|
||||
assert_equal 2, @tournament.matches.select{|m| m.bracket_position == "Semis"}.count, "After deleting a mat there should still be 2 matches for bracket position Semis"
|
||||
assert_equal 4, @tournament.matches.select{|m| m.bracket_position == "Conso Round of 8.2"}.count, "After deleting a mat there should still be 4 matches for bracket position Conso Round of 8.2"
|
||||
assert_equal 2, @tournament.matches.select{|m| m.bracket_position == "Conso Quarter"}.count, "After deleting a mat there should still be 2 matches for bracket position Conso Quarter"
|
||||
assert_equal 2, @tournament.matches.select{|m| m.bracket_position == "Conso Semis"}.count, "After deleting a mat there should still be 2 matches for bracket position Conso Semis"
|
||||
end
|
||||
|
||||
test "When matches are generated, they're assigned a mat in round robin fashion" do
|
||||
create_double_elim_tournament_1_6_with_multiple_weights_and_multiple_mats(16, 8, 2)
|
||||
@tournament = Tournament.find(@tournament.id)
|
||||
|
||||
@tournament.reload
|
||||
@tournament.matches.reload
|
||||
@tournament.reset_and_fill_bout_board
|
||||
@tournament = Tournament.find(@tournament.id)
|
||||
mat1 = @tournament.mats.order(:id).first
|
||||
mat2 = @tournament.mats.order(:id).second
|
||||
mat1.reload
|
||||
mat2.reload
|
||||
matches_ordered_by_bout = @tournament.matches.sort_by{|m| m.bout_number}
|
||||
|
||||
assert_equal matches_ordered_by_bout.first.bout_number, mat1.queue1_match.bout_number, "The first bout number of the tournament should be queue1 on mat 1"
|
||||
assert_equal matches_ordered_by_bout.second.bout_number, mat2.queue1_match.bout_number, "The second bout number of the tournament should be queue1 on mat 2"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finishable_match_scope(tournament)
|
||||
Match.where(tournament_id: tournament.id, finished: [nil, 0])
|
||||
.where.not(w1: nil)
|
||||
.where.not(w2: nil)
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
end
|
||||
|
||||
def next_queued_finishable_match(tournament)
|
||||
tournament.mats.order(:id).each do |mat|
|
||||
match = mat.queue1_match
|
||||
next unless match
|
||||
next unless match.finished != 1
|
||||
return match if match.w1.present? && match.w2.present?
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def assert_queue_depth_matches_available_bouts(tournament)
|
||||
available_count = finishable_match_scope(tournament).count
|
||||
queue_capacity = tournament.mats.count * 4
|
||||
expected_queued_count = [available_count, queue_capacity].min
|
||||
|
||||
queued_ids = tournament.mats.order(:id).flat_map(&:queue_match_ids).compact
|
||||
assert_equal expected_queued_count, queued_ids.count,
|
||||
"Queue depth should match available matches (expected #{expected_queued_count}, got #{queued_ids.count})"
|
||||
|
||||
tournament.mats.order(:id).each do |mat|
|
||||
assert_queue_has_no_gaps(mat)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_queue_has_no_gaps(mat)
|
||||
if mat.queue2.present?
|
||||
assert mat.queue1.present?, "Mat #{mat.id} queue1 must be present when queue2 is present"
|
||||
assert_equal mat.id, mat.queue1_match.mat_id, "The match in queue1 should have a mat_id"
|
||||
end
|
||||
if mat.queue3.present?
|
||||
assert mat.queue2.present?, "Mat #{mat.id} queue2 must be present when queue3 is present"
|
||||
assert_equal mat.id, mat.queue2_match.mat_id, "The match in queue2 should have a mat_id"
|
||||
end
|
||||
if mat.queue4.present?
|
||||
assert mat.queue3.present?, "Mat #{mat.id} queue3 must be present when queue4 is present"
|
||||
assert_equal mat.id, mat.queue3_match.mat_id, "The match in queue3 should have a mat_id"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -31,8 +31,11 @@ class DoubleEliminationAutoByes < ActionDispatch::IntegrationTest
|
||||
assert round1.select{|m| m.bracket_position_number == 4}.first.wrestler1.name == "Test2"
|
||||
assert round1.select{|m| m.bracket_position_number == 4}.first.loser2_name == "BYE"
|
||||
winner_by_name("Test4", round1.select{|m| m.bracket_position_number == 2}.first)
|
||||
assert mat.reload.unfinished_matches.first.loser1_name != "BYE"
|
||||
assert mat.reload.unfinished_matches.first.loser2_name != "BYE"
|
||||
queued_match = mat.reload.queue1_match
|
||||
if queued_match
|
||||
assert queued_match.loser1_name != "BYE"
|
||||
assert queued_match.loser2_name != "BYE"
|
||||
end
|
||||
|
||||
semis = matches.select{|m| m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}
|
||||
assert semis.first.reload.wrestler1.name == "Test1"
|
||||
@@ -40,11 +43,17 @@ class DoubleEliminationAutoByes < ActionDispatch::IntegrationTest
|
||||
assert semis.second.reload.wrestler1.name == "Test3"
|
||||
assert semis.second.reload.wrestler2.name == "Test2"
|
||||
winner_by_name("Test4",semis.first)
|
||||
assert mat.reload.unfinished_matches.first.loser1_name != "BYE"
|
||||
assert mat.reload.unfinished_matches.first.loser2_name != "BYE"
|
||||
queued_match = mat.reload.queue1_match
|
||||
if queued_match
|
||||
assert queued_match.loser1_name != "BYE"
|
||||
assert queued_match.loser2_name != "BYE"
|
||||
end
|
||||
winner_by_name("Test2",semis.second)
|
||||
assert mat.reload.unfinished_matches.first.loser1_name != "BYE"
|
||||
assert mat.reload.unfinished_matches.first.loser2_name != "BYE"
|
||||
queued_match = mat.reload.queue1_match
|
||||
if queued_match
|
||||
assert queued_match.loser1_name != "BYE"
|
||||
assert queued_match.loser2_name != "BYE"
|
||||
end
|
||||
|
||||
conso_quarter = matches.select{|m| m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}
|
||||
assert conso_quarter.first.reload.loser1_name == "BYE"
|
||||
@@ -58,8 +67,11 @@ class DoubleEliminationAutoByes < ActionDispatch::IntegrationTest
|
||||
assert conso_semis.second.reload.wrestler1.name == "Test1"
|
||||
assert conso_semis.second.reload.loser2_name == "BYE"
|
||||
winner_by_name("Test5",conso_semis.first)
|
||||
assert mat.reload.unfinished_matches.first.loser1_name != "BYE"
|
||||
assert mat.reload.unfinished_matches.first.loser2_name != "BYE"
|
||||
queued_match = mat.reload.queue1_match
|
||||
if queued_match
|
||||
assert queued_match.loser1_name != "BYE"
|
||||
assert queued_match.loser2_name != "BYE"
|
||||
end
|
||||
|
||||
first_finals = matches.select{|m| m.bracket_position == "1/2"}.first
|
||||
third_finals = matches.select{|m| m.bracket_position == "3/4"}.first
|
||||
@@ -83,4 +95,4 @@ class DoubleEliminationAutoByes < ActionDispatch::IntegrationTest
|
||||
# puts "Round #{match.round} #{match.w1_bracket_name} vs #{match.w2_bracket_name}"
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,8 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
|
||||
test "Mat assignment works with no mat assignment rules" do
|
||||
@tournament.reset_and_fill_bout_board
|
||||
assert @tournament.mats.first.matches.first != nil
|
||||
assert @tournament.mats.first.queue1_match != nil
|
||||
assert @tournament.mats.second.queue1_match != nil
|
||||
end
|
||||
|
||||
test "Mat assignment only assigns matches for a certain weight" do
|
||||
@@ -25,7 +26,7 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.matches.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
|
||||
assert_not_empty assigned_matches, "Matches should have been assigned to the mat"
|
||||
assert assigned_matches.all? { |match| match.weight_id == assignment_weight_id },
|
||||
@@ -46,8 +47,15 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.matches.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
|
||||
assert_empty assigned_matches, "Matches should not be assigned at tournament start for round 2"
|
||||
|
||||
finish_matches_through_round(@tournament, 1)
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
assert_not_empty assigned_matches, "Matches should have been assigned to the mat"
|
||||
assert assigned_matches.all? { |match| match.round == 2 },
|
||||
"All matches assigned to the mat should only be for round 2"
|
||||
@@ -67,8 +75,15 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.matches.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
|
||||
assert_empty assigned_matches, "Matches should not be assigned at tournament start for bracket position 1/2"
|
||||
|
||||
finish_matches_through_final_round(@tournament)
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
assert_not_empty assigned_matches, "Matches should have been assigned to the mat"
|
||||
assert assigned_matches.all? { |match| match.bracket_position == '1/2' },
|
||||
"All matches assigned to the mat should only be for bracket_position 1/2"
|
||||
@@ -102,10 +117,16 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.matches.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
|
||||
assert_empty assigned_matches, "Matches should not be assigned at tournament start for finals rules"
|
||||
|
||||
finish_matches_through_final_round(@tournament)
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
assert_not_empty assigned_matches, "Matches should have been assigned to the mat"
|
||||
|
||||
assert(
|
||||
assigned_matches.all? do |match|
|
||||
match.weight_id == assignment_weight_id &&
|
||||
@@ -130,7 +151,7 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.matches.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
|
||||
assert_empty assigned_matches, "No matches should have been assigned to the mat"
|
||||
end
|
||||
@@ -159,17 +180,25 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
mat1.reload
|
||||
mat2.reload
|
||||
|
||||
mat1_matches = mat1.matches.reload
|
||||
mat2_matches = mat2.matches.reload
|
||||
mat1_matches = mat1.queue_matches.compact
|
||||
mat2_matches = mat2.queue_matches.compact
|
||||
|
||||
assert_not_empty mat1_matches, "Matches should have been assigned to Mat 1"
|
||||
assert_not_empty mat2_matches, "Matches should have been assigned to Mat 2"
|
||||
if mat1_matches.empty?
|
||||
eligible_matches = @tournament.matches.where(weight_id: @tournament.weights.first.id).where.not(w1: nil).where.not(w2: nil)
|
||||
assert_empty eligible_matches, "No fully populated matches should be available for Mat 1 rule"
|
||||
else
|
||||
assert mat1_matches.all? { |match| match.weight_id == @tournament.weights.first.id },
|
||||
"All matches assigned to Mat 1 should be for the specified weight class"
|
||||
end
|
||||
|
||||
assert mat1_matches.all? { |match| match.weight_id == @tournament.weights.first.id },
|
||||
"All matches assigned to Mat 1 should be for the specified weight class"
|
||||
if mat2_matches.empty?
|
||||
eligible_matches = @tournament.matches.where(round: 3).where.not(w1: nil).where.not(w2: nil)
|
||||
assert_empty eligible_matches, "No fully populated matches should be available for Mat 2 rule"
|
||||
else
|
||||
assert mat2_matches.all? { |match| match.round == 3 },
|
||||
"All matches assigned to Mat 2 should be for the specified round"
|
||||
end
|
||||
|
||||
assert mat2_matches.all? { |match| match.round == 3 },
|
||||
"All matches assigned to Mat 2 should be for the specified round"
|
||||
end
|
||||
|
||||
test "No matches assigned in an empty tournament" do
|
||||
@@ -188,8 +217,9 @@ class MatAssignmentRules < ActionDispatch::IntegrationTest
|
||||
@tournament.reset_and_fill_bout_board
|
||||
|
||||
mat.reload
|
||||
assigned_matches = mat.matches.reload
|
||||
assigned_matches = mat.queue_matches.compact
|
||||
|
||||
assert_empty assigned_matches, "No matches should have been assigned for an empty tournament"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -376,6 +376,27 @@ class ActiveSupport::TestCase
|
||||
Match.where("(w1 = ? OR w2 = ?) AND (w1 = ? OR w2 = ?)",translate_name_to_id(wrestler1_name), translate_name_to_id(wrestler1_name), translate_name_to_id(wrestler2_name),translate_name_to_id(wrestler2_name)).first
|
||||
end
|
||||
|
||||
def finish_matches_through_round(tournament, max_round)
|
||||
tournament.matches.reload.select { |match| match.round && match.round <= max_round }.each do |match|
|
||||
next if match.finished == 1
|
||||
winner_id = match.w1 || match.w2
|
||||
next unless winner_id
|
||||
match.update!(
|
||||
finished: 1,
|
||||
winner_id: winner_id,
|
||||
win_type: "Decision",
|
||||
score: "1-0"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def finish_matches_through_final_round(tournament)
|
||||
last_round = tournament.matches.maximum(:round)
|
||||
return unless last_round
|
||||
|
||||
finish_matches_through_round(tournament, last_round - 1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Add support for controller tests
|
||||
|
||||
@@ -8,13 +8,12 @@ class MatsCurrentMatchPartialTest < ActionView::TestCase
|
||||
mat = @tournament.mats.create!(name: "Mat 1")
|
||||
match = @tournament.matches.first
|
||||
|
||||
match.update!(mat: mat)
|
||||
mat.assign_match_to_queue!(match, 1)
|
||||
|
||||
render partial: "mats/current_match", locals: { mat: mat }
|
||||
|
||||
assert_includes rendered, "Bout"
|
||||
assert_includes rendered, match.bout_number.to_s
|
||||
assert_includes rendered, mat.name
|
||||
end
|
||||
|
||||
test "renders friendly message when no matches assigned" do
|
||||
|
||||
Reference in New Issue
Block a user