mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
Fixed a number of N+1 issues on low traffic pages. I also added relevant html tests for these pages.
This commit is contained in:
@@ -4,7 +4,7 @@ class MatAssignmentRulesController < ApplicationController
|
||||
before_action :set_mat_assignment_rule, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@mat_assignment_rules = @tournament.mat_assignment_rules
|
||||
@mat_assignment_rules = @tournament.mat_assignment_rules.includes(:mat)
|
||||
@weights_by_id = @tournament.weights.index_by(&:id) # For quick lookup
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
class StaticPagesController < ApplicationController
|
||||
|
||||
def my_tournaments
|
||||
tournaments_created = current_user.tournaments
|
||||
tournaments_delegated = current_user.delegated_tournaments
|
||||
tournaments_created = current_user.tournaments.to_a
|
||||
tournaments_delegated = current_user.delegated_tournaments.to_a
|
||||
all_tournaments = tournaments_created + tournaments_delegated
|
||||
@tournaments = all_tournaments.sort_by{|t| t.days_until_start}
|
||||
@schools = current_user.delegated_schools
|
||||
@schools = current_user.delegated_schools.includes(:tournament)
|
||||
end
|
||||
|
||||
def not_allowed
|
||||
|
||||
@@ -7,7 +7,7 @@ class TournamentsController < ApplicationController
|
||||
before_action :check_access_read, only: [:all_results,:up_matches,:bracket,:all_brackets]
|
||||
|
||||
def weigh_in_sheet
|
||||
|
||||
@schools = @tournament.schools.includes(wrestlers: :weight)
|
||||
end
|
||||
|
||||
def calculate_team_scores
|
||||
@@ -92,12 +92,9 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
@users_delegates = []
|
||||
@tournament.schools.each do |s|
|
||||
s.delegates.each do |d|
|
||||
@users_delegates << d
|
||||
end
|
||||
end
|
||||
@users_delegates = SchoolDelegate.includes(:user, :school)
|
||||
.joins(:school)
|
||||
.where(schools: { tournament_id: @tournament.id })
|
||||
end
|
||||
|
||||
def delegate
|
||||
@@ -115,11 +112,13 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
@users_delegates = @tournament.delegates
|
||||
@users_delegates = @tournament.delegates.includes(:user)
|
||||
end
|
||||
|
||||
def matches
|
||||
@matches = @tournament.matches.includes(:wrestlers,:schools).sort_by{|m| m.bout_number}
|
||||
@matches = @tournament.matches
|
||||
.includes({ wrestler1: :school }, { wrestler2: :school }, { weight: :matches })
|
||||
.order(:bout_number)
|
||||
if @match
|
||||
@w1 = @match.wrestler1
|
||||
@w2 = @match.wrestler2
|
||||
@@ -129,10 +128,18 @@ class TournamentsController < ApplicationController
|
||||
|
||||
def weigh_in_weight
|
||||
if params[:wrestler]
|
||||
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
|
||||
sanitized_wrestlers = params.require(:wrestler).to_unsafe_h.each_with_object({}) do |(wrestler_id, attributes), result|
|
||||
permitted = ActionController::Parameters.new(attributes).permit(:offical_weight)
|
||||
result[wrestler_id] = permitted
|
||||
end
|
||||
Wrestler.update(sanitized_wrestlers.keys, sanitized_wrestlers.values) if sanitized_wrestlers.present?
|
||||
redirect_to "/tournaments/#{@tournament.id}/weigh_in/#{params[:weight]}", notice: "Weights were successfully recorded."
|
||||
return
|
||||
end
|
||||
if params[:weight]
|
||||
@weight = Weight.where(:id => params[:weight]).includes(:wrestlers).first
|
||||
@weight = Weight.where(id: params[:weight])
|
||||
.includes(wrestlers: [:school, :weight])
|
||||
.first
|
||||
@tournament_id = @tournament.id
|
||||
@tournament_name = @tournament.name
|
||||
@weights = @tournament.weights
|
||||
@@ -159,8 +166,11 @@ class TournamentsController < ApplicationController
|
||||
def all_brackets
|
||||
@schools = @tournament.schools
|
||||
@schools = @schools.sort_by{|s| s.page_score_string}.reverse!
|
||||
@matches = @tournament.matches.includes(:wrestlers,:schools)
|
||||
@weights = @tournament.weights.includes(:matches,:wrestlers)
|
||||
@weights = @tournament.weights.includes(:matches, wrestlers: :school)
|
||||
all_matches = @tournament.matches.includes(:weight, { wrestler1: :school }, { wrestler2: :school })
|
||||
all_wrestlers = @tournament.wrestlers.includes(:school, :weight)
|
||||
@matches_by_weight_id = all_matches.group_by(&:weight_id)
|
||||
@wrestlers_by_weight_id = all_wrestlers.group_by(&:weight_id)
|
||||
end
|
||||
|
||||
def bracket
|
||||
@@ -210,18 +220,31 @@ class TournamentsController < ApplicationController
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
.order('bout_number ASC')
|
||||
.limit(10).includes(:wrestlers)
|
||||
.limit(10)
|
||||
.includes({ wrestler1: :school }, { wrestler2: :school }, { weight: :matches })
|
||||
@mats = @tournament.mats.includes(:matches)
|
||||
end
|
||||
|
||||
def bout_sheets
|
||||
matches_scope = @tournament.matches
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
|
||||
if params[:round]
|
||||
round = params[:round]
|
||||
if round != "All"
|
||||
@matches = @tournament.matches.where("round = ?",round).sort_by{|match| match.bout_number}
|
||||
@matches = matches_scope
|
||||
.where(round: round)
|
||||
.includes(:weight)
|
||||
.order(:bout_number)
|
||||
else
|
||||
@matches = @tournament.matches.sort_by{|match| match.bout_number}
|
||||
@matches = matches_scope
|
||||
.includes(:weight)
|
||||
.order(:bout_number)
|
||||
end
|
||||
|
||||
wrestler_ids = @matches.flat_map { |match| [match.w1, match.w2] }.compact.uniq
|
||||
@wrestlers_by_id = Wrestler.includes(:school).where(id: wrestler_ids).index_by(&:id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -96,7 +96,9 @@ class Mat < ApplicationRecord
|
||||
@queue_matches = if ids.empty?
|
||||
[nil, nil, nil, nil]
|
||||
else
|
||||
matches_by_id = Match.where(id: ids).index_by(&:id)
|
||||
matches_by_id = Match.where(id: ids)
|
||||
.includes({ wrestler1: :school }, { wrestler2: :school }, { weight: :matches })
|
||||
.index_by(&:id)
|
||||
slot_ids.map { |match_id| match_id ? matches_by_id[match_id] : nil }
|
||||
end
|
||||
@queue_match_slot_ids = slot_ids
|
||||
|
||||
@@ -5,6 +5,8 @@ class Match < ApplicationRecord
|
||||
belongs_to :weight, touch: true
|
||||
belongs_to :mat, touch: true, optional: true
|
||||
belongs_to :winner, class_name: 'Wrestler', foreign_key: 'winner_id', optional: true
|
||||
belongs_to :wrestler1, class_name: 'Wrestler', foreign_key: 'w1', optional: true
|
||||
belongs_to :wrestler2, class_name: 'Wrestler', foreign_key: 'w2', optional: true
|
||||
has_many :wrestlers, :through => :weight
|
||||
has_many :schools, :through => :wrestlers
|
||||
validate :score_validation, :win_type_validation, :bracket_position_validation, :overtime_type_validation
|
||||
@@ -178,14 +180,6 @@ class Match < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def wrestler1
|
||||
wrestlers.select{|w| w.id == self.w1}.first
|
||||
end
|
||||
|
||||
def wrestler2
|
||||
wrestlers.select{|w| w.id == self.w2}.first
|
||||
end
|
||||
|
||||
def w1_name
|
||||
if self.w1 != nil
|
||||
wrestler1.name
|
||||
@@ -203,7 +197,7 @@ class Match < ApplicationRecord
|
||||
end
|
||||
|
||||
def w1_bracket_name
|
||||
first_round = self.weight.matches.sort_by{|m| m.round}.first.round
|
||||
first_round = first_round_for_weight
|
||||
return_string = ""
|
||||
return_string_ending = ""
|
||||
if self.w1 and self.winner_id == self.w1
|
||||
@@ -223,7 +217,7 @@ class Match < ApplicationRecord
|
||||
end
|
||||
|
||||
def w2_bracket_name
|
||||
first_round = self.weight.matches.sort_by{|m| m.round}.first.round
|
||||
first_round = first_round_for_weight
|
||||
return_string = ""
|
||||
return_string_ending = ""
|
||||
if self.w2 and self.winner_id == self.w2
|
||||
@@ -289,6 +283,17 @@ class Match < ApplicationRecord
|
||||
self.weight.max
|
||||
end
|
||||
|
||||
def first_round_for_weight
|
||||
return @first_round_for_weight if defined?(@first_round_for_weight)
|
||||
|
||||
@first_round_for_weight =
|
||||
if association(:weight).loaded? && self.weight&.association(:matches)&.loaded?
|
||||
self.weight.matches.map(&:round).compact.min
|
||||
else
|
||||
Match.where(weight_id: self.weight_id).minimum(:round)
|
||||
end
|
||||
end
|
||||
|
||||
def replace_loser_name_with_wrestler(w,loser_name)
|
||||
if self.loser1_name == loser_name
|
||||
self.w1 = w.id
|
||||
|
||||
@@ -97,18 +97,11 @@ class Tournament < ApplicationRecord
|
||||
end
|
||||
|
||||
def pointAdjustments
|
||||
point_adjustments = []
|
||||
self.schools.each do |s|
|
||||
s.deductedPoints.each do |d|
|
||||
point_adjustments << d
|
||||
end
|
||||
end
|
||||
self.wrestlers.each do |w|
|
||||
w.deductedPoints.each do |d|
|
||||
point_adjustments << d
|
||||
end
|
||||
end
|
||||
point_adjustments
|
||||
school_scope = Teampointadjust.where(school_id: schools.select(:id))
|
||||
wrestler_scope = Teampointadjust.where(wrestler_id: wrestlers.select(:id))
|
||||
|
||||
Teampointadjust.includes(:school, :wrestler)
|
||||
.merge(school_scope.or(wrestler_scope))
|
||||
end
|
||||
|
||||
def remove_school_delegations
|
||||
|
||||
@@ -53,19 +53,16 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def delegated_tournaments
|
||||
tournaments_delegated = []
|
||||
delegated_tournament_permissions.each do |t|
|
||||
tournaments_delegated << t.tournament
|
||||
end
|
||||
tournaments_delegated
|
||||
Tournament.joins(:delegates)
|
||||
.where(tournament_delegates: { user_id: id })
|
||||
.distinct
|
||||
end
|
||||
|
||||
def delegated_schools
|
||||
schools_delegated = []
|
||||
delegated_school_permissions.each do |t|
|
||||
schools_delegated << t.school
|
||||
end
|
||||
schools_delegated
|
||||
School.joins(:delegates)
|
||||
.where(school_delegates: { user_id: id })
|
||||
.includes(:tournament)
|
||||
.distinct
|
||||
end
|
||||
|
||||
def self.search(search)
|
||||
|
||||
@@ -95,8 +95,6 @@ table.smallText tr td { font-size: 10px; }
|
||||
<table class='smallText'>
|
||||
<tr>
|
||||
<td valign="top" style="padding: 10px;">
|
||||
<% @matches = @tournament.matches.select{|m| m.weight_id == @weight.id} %>
|
||||
<% @wrestlers = Wrestler.where(weight_id: @weight.id) %>
|
||||
<% @pools = @weight.pool_rounds(@matches) %>
|
||||
<%= render 'pool' %>
|
||||
</td>
|
||||
|
||||
@@ -119,16 +119,17 @@
|
||||
<% @weights.sort_by{|w| w.max}.each do |weight| %>
|
||||
<% if @tournament.tournament_type == "Pool to bracket" %>
|
||||
<!-- Need to define what the tournaments#bracket controller defines -->
|
||||
<% @matches = @tournament.matches.select{|m| m.weight_id == weight.id} %>
|
||||
<% @wrestlers = Wrestler.where(weight_id: weight.id) %>
|
||||
<% @matches = @matches_by_weight_id[weight.id] || [] %>
|
||||
<% @wrestlers = @wrestlers_by_weight_id[weight.id] || [] %>
|
||||
<% @pools = weight.pool_rounds(@matches) %>
|
||||
<% @weight = weight %>
|
||||
<%= render 'bracket_partial' %>
|
||||
<% elsif @tournament.tournament_type.include? "Modified 16 Man Double Elimination" or @tournament.tournament_type.include? "Regular Double Elimination" %>
|
||||
<!-- Need to define what the tournaments#bracket controller defines -->
|
||||
<% @matches = weight.matches %>
|
||||
<% @matches = @matches_by_weight_id[weight.id] || [] %>
|
||||
<% @wrestlers = @wrestlers_by_weight_id[weight.id] || [] %>
|
||||
<% @weight = weight %>
|
||||
<%= render 'bracket_partial' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -54,28 +54,28 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<% @matches.each do |match| %>
|
||||
<% if match.w1 && match.w2 %>
|
||||
<% w1 = Wrestler.find(match.w1) %>
|
||||
<% w2 = Wrestler.find(match.w2) %>
|
||||
<% end %>
|
||||
|
||||
<div class="pagebreak">
|
||||
<p><strong>Bout Number:</strong> <%= match.bout_number %> <strong>Weight Class:</strong> <%= match.weight.max %> <strong>Round:</strong> <%= match.round %> <strong>Bracket Position:</strong> <%= match.bracket_position %></p>
|
||||
<p><strong>Key: </strong>Takedown: T3, Escape: E1, Reversal: R2, Nearfall: N2 or N3 or N4, Stalling: S, Caution: C, Penalty Point: P1</p>
|
||||
<% @matches.each do |match| %>
|
||||
<% w1 = @wrestlers_by_id[match.w1] %>
|
||||
<% w2 = @wrestlers_by_id[match.w2] %>
|
||||
<% w1_name = w1&.name || match.loser1_name %>
|
||||
<% w2_name = w2&.name || match.loser2_name %>
|
||||
|
||||
<div class="pagebreak">
|
||||
<p><strong>Bout Number:</strong> <%= match.bout_number %> <strong>Weight Class:</strong> <%= match.weight.max %> <strong>Round:</strong> <%= match.round %> <strong>Bracket Position:</strong> <%= match.bracket_position %></p>
|
||||
<p><strong>Key: </strong>Takedown: T3, Escape: E1, Reversal: R2, Nearfall: N2 or N3 or N4, Stalling: S, Caution: C, Penalty Point: P1</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr class="small-row">
|
||||
<th class="fixed-width">Circle Winner</th>
|
||||
<th>
|
||||
<p><%= match.w1_name %>-<%= w1&.school&.name %></p>
|
||||
</th>
|
||||
<th>
|
||||
<p><%= match.w2_name %>-<%= w2&.school&.name %></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<th class="fixed-width">Circle Winner</th>
|
||||
<th>
|
||||
<p><%= w1_name %>-<%= w1&.school&.name %></p>
|
||||
</th>
|
||||
<th>
|
||||
<p><%= w2_name %>-<%= w2&.school&.name %></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="small-row">
|
||||
<td class="fixed-width"></td>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
{
|
||||
"tournament": {
|
||||
"attributes": <%= @tournament.attributes.to_json %>,
|
||||
<%
|
||||
wrestlers_by_id = @tournament.wrestlers.index_by(&:id)
|
||||
weights_by_id = @tournament.weights.index_by(&:id)
|
||||
mats_by_id = @tournament.mats.index_by(&:id)
|
||||
sorted_matches = @tournament.matches.sort_by(&:bout_number)
|
||||
%>
|
||||
{
|
||||
"tournament": {
|
||||
"attributes": <%= @tournament.attributes.to_json %>,
|
||||
"schools": <%= @tournament.schools.map(&:attributes).to_json %>,
|
||||
"weights": <%= @tournament.weights.map(&:attributes).to_json %>,
|
||||
"mats": <%= @tournament.mats.map { |mat| mat.attributes.merge(
|
||||
@@ -14,14 +20,14 @@
|
||||
"weight": wrestler.weight&.attributes
|
||||
}
|
||||
) }.to_json %>,
|
||||
"matches": <%= @tournament.matches.sort_by(&:bout_number).map { |match| match.attributes.merge(
|
||||
{
|
||||
"w1_name": Wrestler.find_by(id: match.w1)&.name,
|
||||
"w2_name": Wrestler.find_by(id: match.w2)&.name,
|
||||
"winner_name": Wrestler.find_by(id: match.winner_id)&.name,
|
||||
"weight": Weight.find_by(id: match.weight_id)&.attributes,
|
||||
"mat": Mat.find_by(id: match.mat_id)&.attributes
|
||||
}
|
||||
) }.to_json %>
|
||||
}
|
||||
"matches": <%= sorted_matches.map { |match| match.attributes.merge(
|
||||
{
|
||||
"w1_name": wrestlers_by_id[match.w1]&.name,
|
||||
"w2_name": wrestlers_by_id[match.w2]&.name,
|
||||
"winner_name": wrestlers_by_id[match.winner_id]&.name,
|
||||
"weight": weights_by_id[match.weight_id]&.attributes,
|
||||
"mat": mats_by_id[match.mat_id]&.attributes
|
||||
}
|
||||
) }.to_json %>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
height: 1in;
|
||||
}
|
||||
</style>
|
||||
<% @tournament.schools.each do |school| %>
|
||||
<% @schools.each do |school| %>
|
||||
<table class="table table-striped table-bordered table-condensed pagebreak">
|
||||
<h5><%= school.name %></h4>
|
||||
<p><strong>Weigh In Ref:</strong> <%= @tournament.weigh_in_ref %></p>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@@ -27,9 +28,9 @@
|
||||
<tr>
|
||||
<td><%= wrestler.name %></td>
|
||||
<td><%= wrestler.weight.max %></td>
|
||||
<td></td>
|
||||
<td><%= wrestler.offical_weight %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<table class="table table-striped table-bordered">
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@@ -9,19 +9,19 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= form_tag @wrestlers_update_path do %>
|
||||
<% @wrestlers.order("original_seed asc").each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<%= form_tag "/tournaments/#{@tournament.id}/weigh_in/#{@weight.id}", method: :post do %>
|
||||
<% @wrestlers.order("original_seed asc").each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<td><%= wrestler.name %></td>
|
||||
<td><%= wrestler.school.name %></td>
|
||||
<td><%= wrestler.original_seed %></td>
|
||||
<td><%= wrestler.weight.max %></td>
|
||||
<td>
|
||||
<% if user_signed_in? %>
|
||||
<%= fields_for "wrestler[]", wrestler do |w| %>
|
||||
<%= w.number_field :offical_weight, :step => 'any' %>
|
||||
<% end %>
|
||||
<% if user_signed_in? %>
|
||||
<%= fields_for "wrestler[#{wrestler.id}]", wrestler do |w| %>
|
||||
<%= w.number_field :offical_weight, :step => 'any' %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= wrestler.offical_weight %>
|
||||
<% end %>
|
||||
|
||||
@@ -215,5 +215,21 @@ class MatAssignmentRulesControllerTest < ActionController::TestCase
|
||||
assert_equal [1, 2, 3], rule.weight_classes
|
||||
assert_equal ['A1', 'B2'], rule.bracket_positions
|
||||
assert_equal [1, 2], rule.rounds
|
||||
end
|
||||
end
|
||||
|
||||
test "index lists created mat assignment rule once in html" do
|
||||
sign_in_owner
|
||||
unique_mat = Mat.create!(name: "Unique Mat #{SecureRandom.hex(4)}", tournament_id: @tournament.id)
|
||||
MatAssignmentRule.create!(
|
||||
mat_id: unique_mat.id,
|
||||
tournament_id: @tournament.id,
|
||||
weight_classes: [1],
|
||||
bracket_positions: ['1/2'],
|
||||
rounds: [2]
|
||||
)
|
||||
|
||||
index
|
||||
assert_response :success
|
||||
assert_equal 1, response.body.scan(unique_mat.name).size
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,4 +36,41 @@ class StaticPagesControllerTest < ActionController::TestCase
|
||||
get :my_tournaments
|
||||
success
|
||||
end
|
||||
|
||||
test "my_tournaments page lists delegated tournament and delegated school once in html" do
|
||||
user = users(:two)
|
||||
sign_in_non_owner
|
||||
|
||||
delegated_tournament = Tournament.create!(
|
||||
name: "Delegated Tournament #{SecureRandom.hex(4)}",
|
||||
address: "123 Delegate St",
|
||||
director: "Director",
|
||||
director_email: "delegate_tournament_#{SecureRandom.hex(4)}@example.com",
|
||||
tournament_type: "Pool to bracket",
|
||||
date: Date.today,
|
||||
is_public: true
|
||||
)
|
||||
TournamentDelegate.create!(tournament_id: delegated_tournament.id, user_id: user.id)
|
||||
|
||||
school_tournament = Tournament.create!(
|
||||
name: "School Tournament #{SecureRandom.hex(4)}",
|
||||
address: "456 School St",
|
||||
director: "Director",
|
||||
director_email: "delegate_school_#{SecureRandom.hex(4)}@example.com",
|
||||
tournament_type: "Pool to bracket",
|
||||
date: Date.today + 1,
|
||||
is_public: true
|
||||
)
|
||||
delegated_school = School.create!(
|
||||
name: "Delegated School #{SecureRandom.hex(4)}",
|
||||
tournament_id: school_tournament.id
|
||||
)
|
||||
SchoolDelegate.create!(school_id: delegated_school.id, user_id: user.id)
|
||||
|
||||
get :my_tournaments
|
||||
assert_response :success
|
||||
assert_equal 1, response.body.scan(delegated_tournament.name).size
|
||||
assert_equal 1, response.body.scan(delegated_school.name).size
|
||||
assert_equal 1, response.body.scan(school_tournament.name).size
|
||||
end
|
||||
end
|
||||
|
||||
@@ -117,6 +117,29 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
sign_in_owner
|
||||
get :weigh_in, params: { id: 1 }
|
||||
success
|
||||
assert_not_includes response.body, "Weights were successfully recorded."
|
||||
end
|
||||
|
||||
test "printable weigh in sheet includes wrestler name school weight class and actual weight" do
|
||||
sign_in_owner
|
||||
@tournament.update!(weigh_in_ref: "Ref Smith")
|
||||
wrestler = @tournament.weights.first.wrestlers.first
|
||||
wrestler.update!(
|
||||
name: "Printable Test Wrestler",
|
||||
offical_weight: 106.4
|
||||
)
|
||||
school = wrestler.school
|
||||
|
||||
get :weigh_in_sheet, params: { id: @tournament.id, print: true }
|
||||
assert_response :success
|
||||
|
||||
assert_includes response.body, school.name
|
||||
assert_includes response.body, "Printable Test Wrestler"
|
||||
assert_includes response.body, wrestler.weight.max.to_s
|
||||
assert_includes response.body, "106.4"
|
||||
assert_includes response.body, "Actual Weight"
|
||||
assert_includes response.body, "Weigh In Ref:"
|
||||
assert_includes response.body, "Ref Smith"
|
||||
end
|
||||
|
||||
test "logged in non tournament owner cannot access weigh_ins" do
|
||||
@@ -155,6 +178,27 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
success
|
||||
end
|
||||
|
||||
test "logged in tournament owner can save wrestler actual weight on weigh in weight page" do
|
||||
sign_in_owner
|
||||
wrestler = @tournament.weights.first.wrestlers.first
|
||||
|
||||
post :weigh_in_weight, params: {
|
||||
id: @tournament.id,
|
||||
weight: wrestler.weight_id,
|
||||
wrestler: {
|
||||
wrestler.id.to_s => { offical_weight: "108.2" }
|
||||
}
|
||||
}
|
||||
|
||||
assert_redirected_to "/tournaments/#{@tournament.id}/weigh_in/#{wrestler.weight_id}"
|
||||
assert_equal "Weights were successfully recorded.", flash[:notice]
|
||||
assert_equal 108.2, wrestler.reload.offical_weight.to_f
|
||||
|
||||
get :weigh_in_weight, params: { id: @tournament.id, weight: wrestler.weight_id }
|
||||
assert_response :success
|
||||
assert_equal 1, response.body.scan("Weights were successfully recorded.").size
|
||||
end
|
||||
|
||||
test "logged in non tournament owner cannot access post weigh_in_weight" do
|
||||
sign_in_non_owner
|
||||
post :weigh_in_weight, params: { id: 1, weight: 1, wrestler: @wrestlers }
|
||||
@@ -685,6 +729,33 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
get :school_delegate, params: { id: 1 }
|
||||
success
|
||||
end
|
||||
|
||||
test "delegate page renders created tournament delegate in html" do
|
||||
user = User.create!(
|
||||
email: "tournament_delegate_render_#{SecureRandom.hex(4)}@example.com",
|
||||
password: "password"
|
||||
)
|
||||
TournamentDelegate.create!(tournament_id: @tournament.id, user_id: user.id)
|
||||
|
||||
sign_in_owner
|
||||
get :delegate, params: { id: @tournament.id }
|
||||
assert_response :success
|
||||
assert_includes response.body, user.email
|
||||
end
|
||||
|
||||
test "school_delegate page renders created school delegate in html" do
|
||||
user = User.create!(
|
||||
email: "school_delegate_render_#{SecureRandom.hex(4)}@example.com",
|
||||
password: "password"
|
||||
)
|
||||
SchoolDelegate.create!(school_id: @school.id, user_id: user.id)
|
||||
|
||||
sign_in_owner
|
||||
get :school_delegate, params: { id: @tournament.id }
|
||||
assert_response :success
|
||||
assert_includes response.body, user.email
|
||||
assert_includes response.body, @school.name
|
||||
end
|
||||
|
||||
test 'logged in tournament owner can delete a school delegate' do
|
||||
sign_in_owner
|
||||
@@ -721,6 +792,16 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
get :teampointadjust, params: { id: 1 }
|
||||
success
|
||||
end
|
||||
|
||||
test "teampointadjust page lists created point deduction once in html" do
|
||||
sign_in_owner
|
||||
school = School.create!(name: "Point Deduction School #{SecureRandom.hex(3)}", tournament_id: @tournament.id)
|
||||
adjustment = Teampointadjust.create!(school_id: school.id, points: 9876.5)
|
||||
|
||||
get :teampointadjust, params: { id: @tournament.id }
|
||||
assert_response :success
|
||||
assert_equal 1, response.body.scan(adjustment.points.to_s).size
|
||||
end
|
||||
|
||||
test 'logged in tournament delegate cannot adjust team points' do
|
||||
sign_in_school_delegate
|
||||
@@ -949,6 +1030,25 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
assert_redirected_to school_delegate_path(@tournament)
|
||||
assert_equal "School permission keys generated successfully.", flash[:notice]
|
||||
end
|
||||
|
||||
test "generated school permission keys are displayed on school delegate page" do
|
||||
sign_in_owner
|
||||
post :generate_school_keys, params: { id: @tournament.id }
|
||||
assert_redirected_to school_delegate_path(@tournament)
|
||||
|
||||
@tournament.schools.reload.each do |school|
|
||||
assert_not_nil school.permission_key, "Expected permission key for school #{school.id}"
|
||||
assert_not_empty school.permission_key, "Expected non-empty permission key for school #{school.id}"
|
||||
end
|
||||
|
||||
get :school_delegate, params: { id: @tournament.id }
|
||||
assert_response :success
|
||||
|
||||
@tournament.schools.each do |school|
|
||||
expected_link_fragment = "/schools/#{school.id}?school_permission_key=#{school.permission_key}"
|
||||
assert_includes response.body, expected_link_fragment
|
||||
end
|
||||
end
|
||||
|
||||
test "tournament delegate can delete school keys" do
|
||||
sign_in_delegate
|
||||
@@ -1180,4 +1280,52 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
expected_page2_display = [expected_page2_size, 20].min
|
||||
assert_equal expected_page2_display, assigns(:tournaments).size, "second page should contain the remaining tournaments (or up to per_page)"
|
||||
end
|
||||
|
||||
test "bout_sheets renders wrestler names, school names, and round for selected round" do
|
||||
tournament = create_double_elim_tournament_single_weight(8, "Regular Double Elimination 1-6")
|
||||
tournament.update!(user_id: users(:one).id, is_public: true)
|
||||
sign_in_owner
|
||||
|
||||
match = tournament.matches.where.not(w1: nil, w2: nil)
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
.order(:bout_number)
|
||||
.first
|
||||
assert_not_nil match, "Expected at least one fully populated non-BYE match"
|
||||
|
||||
round = match.round.to_s
|
||||
w1 = Wrestler.find(match.w1)
|
||||
w2 = Wrestler.find(match.w2)
|
||||
|
||||
get :bout_sheets, params: { id: tournament.id, round: round }
|
||||
assert_response :success
|
||||
|
||||
assert_includes response.body, "Bout Number:</strong> #{match.bout_number}"
|
||||
assert_includes response.body, "Round:</strong> #{match.round}"
|
||||
assert_includes response.body, "#{w1.name}-#{w1.school.name}"
|
||||
assert_includes response.body, "#{w2.name}-#{w2.school.name}"
|
||||
end
|
||||
|
||||
test "bout_sheets filters out matches with BYE loser names" do
|
||||
tournament = create_double_elim_tournament_single_weight(8, "Regular Double Elimination 1-6")
|
||||
tournament.update!(user_id: users(:one).id, is_public: true)
|
||||
sign_in_owner
|
||||
|
||||
bye_match = tournament.matches.order(:bout_number).first
|
||||
assert_not_nil bye_match, "Expected at least one match to mark as BYE"
|
||||
bye_match.update!(loser1_name: "BYE")
|
||||
|
||||
non_bye_match = tournament.matches.where.not(id: bye_match.id).where.not(w1: nil, w2: nil)
|
||||
.where("loser1_name != ? OR loser1_name IS NULL", "BYE")
|
||||
.where("loser2_name != ? OR loser2_name IS NULL", "BYE")
|
||||
.order(:bout_number)
|
||||
.first
|
||||
assert_not_nil non_bye_match, "Expected at least one non-BYE match to remain"
|
||||
|
||||
get :bout_sheets, params: { id: tournament.id, round: "All" }
|
||||
assert_response :success
|
||||
|
||||
assert_not_includes response.body, "Bout Number:</strong> #{bye_match.bout_number}"
|
||||
assert_includes response.body, "Bout Number:</strong> #{non_bye_match.bout_number}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user