1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14: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:
2026-02-03 17:50:52 -05:00
parent a2f8c7bced
commit 2767274066
26 changed files with 1039 additions and 196 deletions

View File

@@ -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

View File

@@ -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