diff --git a/README.md b/README.md index e888608..d00d1df 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,14 @@ From here, you can run the normal rails commands. To deploy a a full local version of the app `bash deploy/deploy-test.sh` (this requires docker-compose to be installed). This deploys a full version of the app. App, delayed job, memcached, and mariadb. Now, you can open [http://localhost](http://localhost). Delayed jobs are turned off in dev and everything that is a delayed job in prod just runs in browser. +To run a single test file: +1. Get a shell with ruby and rails: `bash bin/rails-dev-run.sh wrestlingdev-development` +2. `rake test TEST=test/models/match_test.rb` + +To run a single test inside a file: +1. Get a shell with ruby and rails: `bash bin/rails-dev-run.sh wrestlingdev-development` +2. `rake test TEST=test/models/match_test.rb TESTOPTS="--name='/test_Match_should_not_be_valid_if_an_incorrect_win_type_is_given/'"` + # Deployment The production version of this is currently deployed in Kubernetes. See [Deploying with Kubernetes](deploy/kubernetes/README.md) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 0c6cba6..934add7 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -46,7 +46,7 @@ class MatchesController < ApplicationController end format.json { head :no_content } else - format.html { render action: 'edit' } + format.html { redirect_to session.delete(:return_path), alert: "Match did not save because: #{@match.errors.full_messages.to_s}" } format.json { render json: @match.errors, status: :unprocessable_entity } end end diff --git a/app/models/mat.rb b/app/models/mat.rb index fab782d..c23ec82 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -21,7 +21,7 @@ class Mat < ActiveRecord::Base end def assign_next_match - t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && m.bout_number != nil} + t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && m.bout_number != nil}.sort_by{|m| m.bout_number} if t_matches.size > 0 match = t_matches.sort_by{|m| m.bout_number}.first match.mat_id = self.id diff --git a/app/models/match.rb b/app/models/match.rb index a0006fc..1f99d66 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -4,6 +4,7 @@ class Match < ActiveRecord::Base belongs_to :mat, touch: true has_many :wrestlers, :through => :weight has_many :schools, :through => :wrestlers + validate :score_validation, :win_type_validation, :bracket_position_validation after_update :after_finished_actions, :if => :saved_change_to_finished? or :saved_change_to_winner_id? or :saved_change_to_win_type? or :saved_change_to_score? def after_finished_actions @@ -24,6 +25,34 @@ class Match < ActiveRecord::Base BRACKET_POSITIONS = ["Pool","1/2","3/4","5/6","7/8","Quarter","Semis","Conso Semis","Bracket","Conso", "Conso Quarter"] WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ", "BYE"] + + def score_validation + if finished == 1 + if win_type == "Pin" and ! score.match(/^[0-5]?[0-9]:[0-5][0-9]/) + errors.add(:score, "needs to be in time format MM:SS when win type is Pin example: 1:23 or 10:03") + end + if win_type == "Decision" or win_type == "Tech Fall" or win_type == "Major" and ! score.match(/^[0-9]?[0-9]-[0-9]?[0-9]/) + errors.add(:score, "needs to be in Number-Number format when win type is Decision, Tech Fall, and Major example: 10-2") + end + if (win_type == "Forfeit" or win_type == "Injury Default" or win_type == "Default" or win_type == "BYE" or win_type == "DQ") and (score != "") + errors.add(:score, "needs to be blank when win type is Forfeit, Injury Default, Default, BYE, or DQ win_type") + end + end + end + + def win_type_validation + if finished == 1 + if ! WIN_TYPES.include? win_type + errors.add(:win_type, "can only be one of the following #{WIN_TYPES.to_s}") + end + end + end + + def bracket_position_validation + if ! BRACKET_POSITIONS.include? bracket_position + errors.add(:bracket_position, "can only be one of the following #{BRACKET_POSITIONS.to_s}") + end + end def is_consolation_match if self.bracket_position == "Conso" or self.bracket_position == "Conso Quarter" or self.bracket_position == "Conso Semis" or self.bracket_position == "3/4" or self.bracket_position == "5/6" or self.bracket_position == "7/8" diff --git a/app/services/tournament_services/eight_man_double_elimination_generate_loser_names.rb b/app/services/tournament_services/eight_man_double_elimination_generate_loser_names.rb index 7b46554..a2daeed 100644 --- a/app/services/tournament_services/eight_man_double_elimination_generate_loser_names.rb +++ b/app/services/tournament_services/eight_man_double_elimination_generate_loser_names.rb @@ -52,11 +52,13 @@ class EightManDoubleEliminationGenerateLoserNames if match.w1 != nil match.winner_id = match.w1 match.loser2_name = "BYE" + match.score = "" match.save match.advance_wrestlers elsif match.w2 != nil match.winner_id = match.w2 match.loser1_name = "BYE" + match.score = "" match.save match.advance_wrestlers end diff --git a/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb b/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb index 003c0ad..c72cfa6 100644 --- a/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb +++ b/app/services/tournament_services/modified_sixteen_man_generate_loser_names.rb @@ -72,11 +72,13 @@ class ModifiedSixteenManGenerateLoserNames if match.w1 != nil match.winner_id = match.w1 match.loser2_name = "BYE" + match.score = "" match.save match.advance_wrestlers elsif match.w2 != nil match.winner_id = match.w2 match.loser1_name = "BYE" + match.score = "" match.save match.advance_wrestlers end diff --git a/app/services/tournament_services/sixteen_man_double_elimination_generate_loser_names.rb b/app/services/tournament_services/sixteen_man_double_elimination_generate_loser_names.rb index 6546c19..11cd4e2 100644 --- a/app/services/tournament_services/sixteen_man_double_elimination_generate_loser_names.rb +++ b/app/services/tournament_services/sixteen_man_double_elimination_generate_loser_names.rb @@ -81,11 +81,13 @@ class SixteenManDoubleEliminationGenerateLoserNames if match.w1 != nil match.winner_id = match.w1 match.loser2_name = "BYE" + match.score = "" match.save match.advance_wrestlers elsif match.w2 != nil match.winner_id = match.w2 match.loser1_name = "BYE" + match.score = "" match.save match.advance_wrestlers end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a7cc6de..25de5d9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -40,6 +40,9 @@ <% if notice %>
×<%= notice %>
<% end %> + <% if alert %> +×<%= alert %>
+ <% end %>