From 7ffdd3edf5c5cd96f149b9bb7fd5654812098c5a Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 14 Jan 2020 13:16:34 -0500 Subject: [PATCH] Added button to calculate all team scores --- app/controllers/tournaments_controller.rb | 13 ++++++-- app/views/layouts/_tournament-navbar.html.erb | 1 + config/routes.rb | 1 + .../tournaments_controller_test.rb | 31 ++++++++++++++++--- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 774f980..fb7c2ce 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,6 +1,6 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:import,:export,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets] - before_action :check_access_manage, only: [:import,:export,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches] + before_action :set_tournament, only: [:calculate_team_scores, :import,:export,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets] + before_action :check_access_manage, only: [:calculate_team_scores, :import,:export,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches] before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate] before_action :check_tournament_errors, only: [:generate_matches] before_action :check_for_matches, only: [:up_matches,:bracket,:all_brackets] @@ -13,6 +13,15 @@ class TournamentsController < ApplicationController end + def calculate_team_scores + @tournament.schools.each do |school| + school.calculate_score + end + respond_to do |format| + format.html { redirect_to "/tournaments/#{@tournament.id}", notice: 'Team scores are calcuating.' } + end + end + def import import_text = params[:tournament][:import_text] respond_to do |format| diff --git a/app/views/layouts/_tournament-navbar.html.erb b/app/views/layouts/_tournament-navbar.html.erb index 3ac0caa..5f1ffad 100644 --- a/app/views/layouts/_tournament-navbar.html.erb +++ b/app/views/layouts/_tournament-navbar.html.erb @@ -44,6 +44,7 @@
  • Time Savers
  • <%= link_to "Create High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=hs",data: { confirm: 'Are you sure? This will delete all current weights.' } %>
  • Tournament Actions
  • +
  • <%= link_to "Calculate Team Scores" , "/tournaments/#{@tournament.id}/calculate_team_scores", method: :post %>
  • <%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' } %>
  • <%= link_to "Export Data" , "/tournaments/#{@tournament.id}/export?print=true", target: :_blank %>
  • diff --git a/config/routes.rb b/config/routes.rb index cdfcdb9..0548b68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,7 @@ Wrestling::Application.routes.draw do get 'tournaments/:id/export' => "tournaments#export" post "/tournaments/:id/import" => "tournaments#import", :as => :import get "/tournaments/:id/brackets" => "tournaments#show" + post "/tournaments/:id/calculate_team_scores" => "tournaments#calculate_team_scores" post 'weights/:id/re_gen' => 'weights#re_gen', :as => :regen_weight post "/wrestlers/update_pool" => "wrestlers#update_pool" diff --git a/test/controllers/tournaments_controller_test.rb b/test/controllers/tournaments_controller_test.rb index 371baab..06918ad 100644 --- a/test/controllers/tournaments_controller_test.rb +++ b/test/controllers/tournaments_controller_test.rb @@ -322,11 +322,8 @@ class TournamentsControllerTest < ActionController::TestCase patch :remove_delegate, params: { id: 1, delegate: TournamentDelegate.find(1) } redirect end - - - - - test 'logged in tournament delegate can adjust team points' do + + test 'logged in tournament delegate can adjust team points' do sign_in_delegate get :teampointadjust, params: { id: 1 } success @@ -373,4 +370,28 @@ class TournamentsControllerTest < ActionController::TestCase get :matches, params: { id: 1 } success end + + test "logged in tournament owner can calculate team scores" do + sign_in_owner + post :calculate_team_scores, params: { id: 1 } + success + end + + test "logged in tournament delegate can calculate team scores" do + sign_in_delegate + post :calculate_team_scores, params: { id: 1 } + success + end + + test "logged in non tournament owner cannot calculate team scores" do + sign_in_non_owner + post :calculate_team_scores, params: { id: 1 } + redirect + end + + test "logged in school delegate cannot calculate team scores" do + sign_in_school_delegate + post :calculate_team_scores, params: { id: 1 } + redirect + end end