From 698576dac943a9d4503ce6753a5eeed2164ed3fa Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Sat, 4 Jan 2025 16:26:57 -0500 Subject: [PATCH] Fixed the POSt endpoint to accept bracket positions --- .../mat_assignment_rules_controller.rb | 1 - .../mat_assignment_rules_controller_test.rb | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/mat_assignment_rules_controller.rb b/app/controllers/mat_assignment_rules_controller.rb index 4fda349..b8e02eb 100644 --- a/app/controllers/mat_assignment_rules_controller.rb +++ b/app/controllers/mat_assignment_rules_controller.rb @@ -68,7 +68,6 @@ class MatAssignmentRulesController < ApplicationController # Permit the parameters and convert specific fields to integer arrays params.require(:mat_assignment_rule).permit(:mat_id, weight_classes: [], bracket_positions: [], rounds: []).tap do |whitelisted| whitelisted[:weight_classes] = whitelisted[:weight_classes].map(&:to_i) - whitelisted[:bracket_positions] = whitelisted[:bracket_positions].map(&:to_i) whitelisted[:rounds] = whitelisted[:rounds].map(&:to_i) end end diff --git a/test/controllers/mat_assignment_rules_controller_test.rb b/test/controllers/mat_assignment_rules_controller_test.rb index d9dddd5..f565d94 100644 --- a/test/controllers/mat_assignment_rules_controller_test.rb +++ b/test/controllers/mat_assignment_rules_controller_test.rb @@ -200,4 +200,19 @@ class MatAssignmentRulesControllerTest < ActionController::TestCase end redirect end + + test "logged in tournament owner should create a rule with bracket positions" do + sign_in_owner + assert_difference 'MatAssignmentRule.count', 1 do + post :create, params: { tournament_id: @tournament.id, mat_assignment_rule: { + mat_id: @mat.id, weight_classes: [1, 2, 3], bracket_positions: ['A1', 'B2'], rounds: [1, 2] + } } + end + assert_redirected_to tournament_mat_assignment_rules_path(@tournament) + + rule = MatAssignmentRule.last + assert_equal [1, 2, 3], rule.weight_classes + assert_equal ['A1', 'B2'], rule.bracket_positions + assert_equal [1, 2], rule.rounds + end end