mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-01 20:25:26 +00:00
Fixed double elim bracket views, fixed double elim match generation and loser name generation for 4 man bracket, fixed seed page submission and added tests, added tests for tournament generation errors and added a new error for assigning a seed higher than the number of wrestlers.
This commit is contained in:
@@ -55,6 +55,10 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
assert_redirected_to '/static_pages/not_allowed'
|
||||
end
|
||||
|
||||
def redirect_tournament_error
|
||||
assert_redirected_to "/tournaments/#{@tournament.id}/error"
|
||||
end
|
||||
|
||||
def destroy
|
||||
delete :destroy, params: { id: 1 }
|
||||
end
|
||||
@@ -664,4 +668,83 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
updated_tournament = Tournament.find(new_tournament.id)
|
||||
assert_equal users(:one).id, updated_tournament.user_id, "The user_id should not change when the tournament is edited by a non-owner"
|
||||
end
|
||||
|
||||
test "tournament generation error when a wrestler has an original seed higher than the amount of wrestlers in the weight" do
|
||||
sign_in_owner
|
||||
create_double_elim_tournament_single_weight(14, "Regular Double Elimination 1-8")
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
wrestler = @tournament.weights.first.wrestlers.first
|
||||
wrestler.original_seed = 15
|
||||
wrestler.save
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
|
||||
test "tournament generation error when a double elimination tournament has too many wrestlers" do
|
||||
sign_in_owner
|
||||
create_double_elim_tournament_single_weight(16, "Regular Double Elimination 1-8")
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
create_wrestlers_for_weight_for_double_elim(@tournament.weights.first, @tournament.schools.first, 1, 20)
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
|
||||
test "tournament generation error when a double elimination tournament has too few wrestlers" do
|
||||
sign_in_owner
|
||||
create_double_elim_tournament_single_weight(4, "Regular Double Elimination 1-8")
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
@tournament.weights.first.wrestlers.first.destroy
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
|
||||
test "tournament generation error when a Modified 16 Man Double Elimination tournament has too many wrestlers" do
|
||||
sign_in_owner
|
||||
create_double_elim_tournament_single_weight(16, "Modified 16 Man Double Elimination 1-8")
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
create_wrestlers_for_weight_for_double_elim(@tournament.weights.first, @tournament.schools.first, 1, 20)
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
|
||||
test "tournament generation error when a Modified 16 Man Double Elimination tournament has too few wrestlers" do
|
||||
sign_in_owner
|
||||
create_double_elim_tournament_single_weight(12, "Modified 16 Man Double Elimination 1-8")
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
@tournament.weights.first.wrestlers.first.destroy
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
|
||||
test "tournament generation error when a pool to bracket tournament has too many wrestlers" do
|
||||
sign_in_owner
|
||||
create_pool_tournament_single_weight(24)
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
create_wrestlers_for_weight(@tournament.weights.first, @tournament.schools.first, 1, 20)
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
|
||||
test "tournament generation error when a pool to bracket tournament has too few wrestlers" do
|
||||
sign_in_owner
|
||||
create_pool_tournament_single_weight(2)
|
||||
@tournament.destroy_all_matches
|
||||
@tournament.user_id = 1
|
||||
@tournament.save
|
||||
@tournament.weights.first.wrestlers.first.destroy
|
||||
get :generate_matches, params: { id: @tournament.id }
|
||||
redirect_tournament_error
|
||||
end
|
||||
end
|
||||
|
||||
@@ -300,4 +300,109 @@ class WeightsControllerTest < ActionController::TestCase
|
||||
success
|
||||
end
|
||||
|
||||
test "tournament owner can update wrestler seeds" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
sign_in_owner
|
||||
|
||||
# Prepare updated seed data for wrestlers
|
||||
updated_seeds = {
|
||||
@wrestler.id.to_s => { original_seed: "5" },
|
||||
@weight.wrestlers.second.id.to_s => { original_seed: "6" },
|
||||
@weight.wrestlers.third.id.to_s => { original_seed: "7" }
|
||||
}
|
||||
|
||||
# Submit the form with the updated seeds
|
||||
post :show, params: { id: @weight.id, wrestler: updated_seeds }
|
||||
|
||||
# Check if response is successful
|
||||
assert_redirected_to weight_path(@weight.id)
|
||||
|
||||
# Reload wrestlers to verify changes
|
||||
@wrestler.reload
|
||||
@weight.wrestlers.second.reload
|
||||
@weight.wrestlers.third.reload
|
||||
|
||||
# Verify seeds are updated
|
||||
assert_equal 5, @wrestler.original_seed
|
||||
assert_equal 6, @weight.wrestlers.second.original_seed
|
||||
assert_equal 7, @weight.wrestlers.third.original_seed
|
||||
end
|
||||
|
||||
test "tournament delegate can update wrestler seeds" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
sign_in_tournament_delegate
|
||||
|
||||
# Prepare updated seed data for wrestlers
|
||||
updated_seeds = {
|
||||
@wrestler.id.to_s => { original_seed: "8" },
|
||||
@weight.wrestlers.second.id.to_s => { original_seed: "9" },
|
||||
@weight.wrestlers.third.id.to_s => { original_seed: "10" }
|
||||
}
|
||||
|
||||
# Submit the form with the updated seeds
|
||||
post :show, params: { id: @weight.id, wrestler: updated_seeds }
|
||||
|
||||
# Check if response is successful
|
||||
assert_redirected_to weight_path(@weight.id)
|
||||
|
||||
# Reload wrestlers to verify changes
|
||||
@wrestler.reload
|
||||
@weight.wrestlers.second.reload
|
||||
@weight.wrestlers.third.reload
|
||||
|
||||
# Verify seeds are updated
|
||||
assert_equal 8, @wrestler.original_seed
|
||||
assert_equal 9, @weight.wrestlers.second.original_seed
|
||||
assert_equal 10, @weight.wrestlers.third.original_seed
|
||||
end
|
||||
|
||||
test "unauthorized user cannot update wrestler seeds" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
sign_in_non_owner
|
||||
|
||||
# Prepare updated seed data for wrestlers
|
||||
updated_seeds = {
|
||||
@wrestler.id.to_s => { original_seed: "11" },
|
||||
@weight.wrestlers.second.id.to_s => { original_seed: "12" }
|
||||
}
|
||||
|
||||
# Attempt to submit the form
|
||||
post :show, params: { id: @weight.id, wrestler: updated_seeds }
|
||||
|
||||
# Check if user is redirected due to lack of permissions
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
# Verify seeds are not updated
|
||||
@wrestler.reload
|
||||
@weight.wrestlers.second.reload
|
||||
assert_not_equal 11, @wrestler.original_seed
|
||||
assert_not_equal 12, @weight.wrestlers.second.original_seed
|
||||
end
|
||||
|
||||
test "non logged in user cannot update wrestler seeds" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
|
||||
# Prepare updated seed data for wrestlers
|
||||
updated_seeds = {
|
||||
@wrestler.id.to_s => { original_seed: "11" },
|
||||
@weight.wrestlers.second.id.to_s => { original_seed: "12" }
|
||||
}
|
||||
|
||||
# Attempt to submit the form
|
||||
post :show, params: { id: @weight.id, wrestler: updated_seeds }
|
||||
|
||||
# Check if user is redirected due to lack of permissions
|
||||
assert_redirected_to "/static_pages/not_allowed"
|
||||
|
||||
# Verify seeds are not updated
|
||||
@wrestler.reload
|
||||
@weight.wrestlers.second.reload
|
||||
assert_not_equal 11, @wrestler.original_seed
|
||||
assert_not_equal 12, @weight.wrestlers.second.original_seed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user