From c5a7bc3815ab5a2e1d2c6445871592025fe05be9 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Sat, 25 Jan 2014 05:28:42 -0500 Subject: [PATCH] A ton of stuff was done to finalize the app for use --- app/assets/javascripts/mats.js.coffee | 3 + app/assets/stylesheets/mats.css.scss | 3 + app/controllers/matches_controller.rb | 27 +- app/controllers/mats_controller.rb | 93 +++++++ app/controllers/schools_controller.rb | 12 + app/controllers/static_pages_controller.rb | 239 ++++++++++++++++++ app/controllers/tournaments_controller.rb | 13 + app/controllers/weights_controller.rb | 16 +- app/controllers/wrestlers_controller.rb | 12 + app/helpers/mats_helper.rb | 2 + app/models/mat.rb | 4 + app/models/match.rb | 1 + app/models/school.rb | 30 ++- app/models/tournament.rb | 2 +- app/views/layouts/_header.html.erb | 3 +- app/views/matches/_edit_form.html.erb | 36 +++ app/views/matches/edit.html.erb | 7 +- app/views/mats/_form.html.erb | 31 +++ app/views/mats/edit.html.erb | 6 + app/views/mats/index.html.erb | 29 +++ app/views/mats/index.json.jbuilder | 4 + app/views/mats/new.html.erb | 5 + app/views/mats/show.html.erb | 13 + app/views/mats/show.json.jbuilder | 1 + app/views/static_pages/_man10.html.erb | 2 +- app/views/static_pages/_man7.html.erb | 1 - app/views/static_pages/_man8.html.erb | 1 - app/views/static_pages/_man9.html.erb | 1 - app/views/static_pages/brackets.html.erb | 1 + .../static_pages/generate_matches.html.erb | 3 + app/views/static_pages/results.html.erb | 105 ++++++++ app/views/static_pages/up_matches.html.erb | 45 ++++ app/views/tournaments/show.html.erb | 33 +++ app/views/weights/_form.html.erb | 7 + config/routes.rb | 8 +- ...0125040820_add_tournament_id_to_matches.rb | 5 + .../20140125062040_add_round_to_match.rb | 5 + db/migrate/20140125065007_create_mats.rb | 10 + .../20140125065443_add_mat_id_to_weights.rb | 5 + ...125072649_add_finished_field_to_matches.rb | 5 + db/schema.rb | 13 +- test/controllers/mats_controller_test.rb | 49 ++++ test/fixtures/mats.yml | 9 + test/helpers/mats_helper_test.rb | 4 + test/models/mat_test.rb | 7 + 45 files changed, 889 insertions(+), 22 deletions(-) create mode 100644 app/assets/javascripts/mats.js.coffee create mode 100644 app/assets/stylesheets/mats.css.scss create mode 100644 app/controllers/mats_controller.rb create mode 100644 app/helpers/mats_helper.rb create mode 100644 app/models/mat.rb create mode 100644 app/views/matches/_edit_form.html.erb create mode 100644 app/views/mats/_form.html.erb create mode 100644 app/views/mats/edit.html.erb create mode 100644 app/views/mats/index.html.erb create mode 100644 app/views/mats/index.json.jbuilder create mode 100644 app/views/mats/new.html.erb create mode 100644 app/views/mats/show.html.erb create mode 100644 app/views/mats/show.json.jbuilder create mode 100644 app/views/static_pages/generate_matches.html.erb create mode 100644 app/views/static_pages/results.html.erb create mode 100644 app/views/static_pages/up_matches.html.erb create mode 100644 db/migrate/20140125040820_add_tournament_id_to_matches.rb create mode 100644 db/migrate/20140125062040_add_round_to_match.rb create mode 100644 db/migrate/20140125065007_create_mats.rb create mode 100644 db/migrate/20140125065443_add_mat_id_to_weights.rb create mode 100644 db/migrate/20140125072649_add_finished_field_to_matches.rb create mode 100644 test/controllers/mats_controller_test.rb create mode 100644 test/fixtures/mats.yml create mode 100644 test/helpers/mats_helper_test.rb create mode 100644 test/models/mat_test.rb diff --git a/app/assets/javascripts/mats.js.coffee b/app/assets/javascripts/mats.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/mats.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/mats.css.scss b/app/assets/stylesheets/mats.css.scss new file mode 100644 index 0000000..92a20d9 --- /dev/null +++ b/app/assets/stylesheets/mats.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Mats controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index eb1a87f..7bcefe4 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -19,11 +19,26 @@ class MatchesController < ApplicationController # GET /matches/1/edit def edit + if user_signed_in? + else + redirect_to root_path + end + if params[:match] + @match = Match.find (params[:match]) + end + if @match + @w1 = Wrestler.find(@match.r_id) + @w2 = Wrestler.find(@match.g_id) + end end # POST /matches # POST /matches.json def create + if user_signed_in? + else + redirect_to root_path + end @match = Match.new(match_params) respond_to do |format| @@ -40,9 +55,13 @@ class MatchesController < ApplicationController # PATCH/PUT /matches/1 # PATCH/PUT /matches/1.json def update + if user_signed_in? + else + redirect_to root_path + end respond_to do |format| if @match.update(match_params) - format.html { redirect_to @match, notice: 'Match was successfully updated.' } + format.html { redirect_to root_path, notice: 'Match was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } @@ -54,6 +73,10 @@ class MatchesController < ApplicationController # DELETE /matches/1 # DELETE /matches/1.json def destroy + if user_signed_in? + else + redirect_to root_path + end @match.destroy respond_to do |format| format.html { redirect_to matches_url } @@ -69,6 +92,6 @@ class MatchesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def match_params - params.require(:match).permit(:r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score) + params.require(:match).permit(:r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score, :finished) end end diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb new file mode 100644 index 0000000..fbe955f --- /dev/null +++ b/app/controllers/mats_controller.rb @@ -0,0 +1,93 @@ +class MatsController < ApplicationController + before_action :set_mat, only: [:show, :edit, :update, :destroy] + + # GET /mats + # GET /mats.json + def index + @mats = Mat.all + end + + # GET /mats/1 + # GET /mats/1.json + def show + end + + # GET /mats/new + def new + @mat = Mat.new + if params[:tournament] + @tournament_field = params[:tournament] + @tournament = Tournament.find(params[:tournament]) + end + end + + # GET /mats/1/edit + def edit + @tournament_field = @mat.tournament_id + end + + # POST /mats + # POST /mats.json + def create + if user_signed_in? + else + redirect_to root_path + end + @mat = Mat.new(mat_params) + @tournament = Tournament.find(mat_params[:tournament_id]) + respond_to do |format| + if @mat.save + format.html { redirect_to @tournament, notice: 'Mat was successfully created.' } + format.json { render action: 'show', status: :created, location: @mat } + else + format.html { render action: 'new' } + format.json { render json: @mat.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /mats/1 + # PATCH/PUT /mats/1.json + def update + if user_signed_in? + else + redirect_to root_path + end + @tournament = Tournament.find(@mat.tournament_id) + respond_to do |format| + if @mat.update(mat_params) + format.html { redirect_to @tournament, notice: 'Mat was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @mat.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /mats/1 + # DELETE /mats/1.json + def destroy + if user_signed_in? + else + redirect_to root_path + end + @tournament = Tournament.find(@mat.tournament_id) + @mat.destroy + respond_to do |format| + format.html { redirect_to @tournament } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_mat + @mat = Mat.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def mat_params + params.require(:mat).permit(:name, :tournament_id) + end +end diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 826426e..5902334 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -31,6 +31,10 @@ class SchoolsController < ApplicationController # POST /schools # POST /schools.json def create + if user_signed_in? + else + redirect_to root_path + end @school = School.new(school_params) @tournament = Tournament.find(school_params[:tournament_id]) respond_to do |format| @@ -47,6 +51,10 @@ class SchoolsController < ApplicationController # PATCH/PUT /schools/1 # PATCH/PUT /schools/1.json def update + if user_signed_in? + else + redirect_to root_path + end @tournament = Tournament.find(@school.tournament_id) respond_to do |format| if @school.update(school_params) @@ -62,6 +70,10 @@ class SchoolsController < ApplicationController # DELETE /schools/1 # DELETE /schools/1.json def destroy + if user_signed_in? + else + redirect_to root_path + end @tournament = Tournament.find(@school.tournament_id) @school.destroy respond_to do |format| diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index fc9a0c3..5449549 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -3,7 +3,25 @@ class StaticPagesController < ApplicationController def index @tournaments = Tournament.all end + def up_matches + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + end + if @tournament + @matches = Weight.where(tournament_id: @tournament.id) + end + @matches = Match.where(finished: nil) + end + def results + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + end + if @tournament + @matches = Weight.where(tournament_id: @tournament.id) + end + @matches = Match.where(finished: 1) + end def brackets if params[:weight] @weight = Weight.find(params[:weight]) @@ -33,5 +51,226 @@ class StaticPagesController < ApplicationController @weights = Weight.where(tournament_id: @tournament.id) end end + + def generate_matches + if user_signed_in? + else + redirect_to root_path + end + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + end + if @tournament + @matches_all = Match.where(tournament_id: @tournament.id) + @matches_all.each do |match| + match.destroy + end + @weights = Weight.where(tournament_id: @tournament.id) + #ROUND 1 + @weights.order("id asc").each do |weight| + @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first + @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first + @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first + @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first + @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first + @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first + @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first + @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first + @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first + @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first + @bracket_size = Wrestler.where(weight_id: weight.id).count + def createMatch(r_id,g_id,tournament) + @match = Match.new + @match.r_id = r_id + @match.g_id = g_id + @match.tournament_id = tournament + @match.round = 1 + @match.save + end + if @bracket_size == 10 + createMatch(@seed1.id,@seed10.id,@tournament.id) + createMatch(@seed5.id,@seed7.id,@tournament.id) + createMatch(@seed2.id,@seed9.id,@tournament.id) + createMatch(@seed6.id,@seed8.id,@tournament.id) + elsif @bracket_size == 9 + createMatch(@seed1.id,@seed9.id,@tournament.id) + createMatch(@seed5.id,@seed7.id,@tournament.id) + createMatch(@seed6.id,@seed8.id,@tournament.id) + elsif @bracket_size == 8 + createMatch(@seed5.id,@seed7.id,@tournament.id) + createMatch(@seed6.id,@seed8.id,@tournament.id) + elsif @bracket_size == 7 + createMatch(@seed5.id,@seed7.id,@tournament.id) + end + + end + #ROUND 2 + @weights.order("id asc").each do |weight| + @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first + @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first + @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first + @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first + @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first + @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first + @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first + @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first + @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first + @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first + @bracket_size = Wrestler.where(weight_id: weight.id).count + def createMatch(r_id,g_id,tournament) + @match = Match.new + @match.r_id = r_id + @match.g_id = g_id + @match.tournament_id = tournament + @match.round = 2 + @match.save + end + if @bracket_size == 10 + createMatch(@seed1.id,@seed5.id,@tournament.id) + createMatch(@seed10.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed6.id,@tournament.id) + createMatch(@seed9.id,@seed3.id,@tournament.id) + elsif @bracket_size == 9 + createMatch(@seed1.id,@seed5.id,@tournament.id) + createMatch(@seed9.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed6.id,@tournament.id) + elsif @bracket_size == 8 + createMatch(@seed1.id,@seed5.id,@tournament.id) + createMatch(@seed2.id,@seed6.id,@tournament.id) + elsif @bracket_size == 7 + createMatch(@seed1.id,@seed5.id,@tournament.id) + createMatch(@seed2.id,@seed6.id,@tournament.id) + end + + end + #ROUND 3 + @weights.order("id asc").each do |weight| + @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first + @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first + @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first + @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first + @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first + @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first + @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first + @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first + @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first + @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first + @bracket_size = Wrestler.where(weight_id: weight.id).count + def createMatch(r_id,g_id,tournament) + @match = Match.new + @match.r_id = r_id + @match.g_id = g_id + @match.tournament_id = tournament + @match.round = 3 + @match.save + end + if @bracket_size == 10 + createMatch(@seed1.id,@seed4.id,@tournament.id) + createMatch(@seed10.id,@seed7.id,@tournament.id) + createMatch(@seed2.id,@seed3.id,@tournament.id) + createMatch(@seed8.id,@seed9.id,@tournament.id) + elsif @bracket_size == 9 + createMatch(@seed1.id,@seed4.id,@tournament.id) + createMatch(@seed9.id,@seed7.id,@tournament.id) + createMatch(@seed2.id,@seed3.id,@tournament.id) + elsif @bracket_size == 8 + createMatch(@seed1.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed3.id,@tournament.id) + elsif @bracket_size == 7 + createMatch(@seed1.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed3.id,@tournament.id) + end + + end + #ROUND 4 + @weights.order("id asc").each do |weight| + @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first + @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first + @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first + @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first + @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first + @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first + @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first + @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first + @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first + @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first + @bracket_size = Wrestler.where(weight_id: weight.id).count + def createMatch(r_id,g_id,tournament) + @match = Match.new + @match.r_id = r_id + @match.g_id = g_id + @match.tournament_id = tournament + @match.round = 4 + @match.save + end + if @bracket_size == 10 + createMatch(@seed1.id,@seed7.id,@tournament.id) + createMatch(@seed5.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed8.id,@tournament.id) + createMatch(@seed6.id,@seed3.id,@tournament.id) + elsif @bracket_size == 9 + createMatch(@seed1.id,@seed7.id,@tournament.id) + createMatch(@seed5.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed8.id,@tournament.id) + createMatch(@seed6.id,@seed3.id,@tournament.id) + elsif @bracket_size == 8 + createMatch(@seed1.id,@seed7.id,@tournament.id) + createMatch(@seed5.id,@seed4.id,@tournament.id) + createMatch(@seed2.id,@seed8.id,@tournament.id) + createMatch(@seed6.id,@seed3.id,@tournament.id) + elsif @bracket_size == 7 + createMatch(@seed1.id,@seed7.id,@tournament.id) + createMatch(@seed5.id,@seed4.id,@tournament.id) + createMatch(@seed6.id,@seed3.id,@tournament.id) + end + + end + #ROUND 5 + @weights.order("id asc").each do |weight| + @seed1 = Wrestler.where(weight_id: weight.id, original_seed: 1).first + @seed10 = Wrestler.where(weight_id: weight.id, original_seed: 10).first + @seed7 = Wrestler.where(weight_id: weight.id, original_seed: 7).first + @seed5 = Wrestler.where(weight_id: weight.id, original_seed: 5).first + @seed4 = Wrestler.where(weight_id: weight.id, original_seed: 4).first + @seed2 = Wrestler.where(weight_id: weight.id, original_seed: 2).first + @seed9 = Wrestler.where(weight_id: weight.id, original_seed: 9).first + @seed6 = Wrestler.where(weight_id: weight.id, original_seed: 6).first + @seed8 = Wrestler.where(weight_id: weight.id, original_seed: 8).first + @seed3 = Wrestler.where(weight_id: weight.id, original_seed: 3).first + @bracket_size = Wrestler.where(weight_id: weight.id).count + def createMatch(r_id,g_id,tournament) + @match = Match.new + @match.r_id = r_id + @match.g_id = g_id + @match.tournament_id = tournament + @match.round = 5 + @match.save + end + if @bracket_size == 10 + createMatch(@seed10.id,@seed5.id,@tournament.id) + createMatch(@seed7.id,@seed4.id,@tournament.id) + createMatch(@seed9.id,@seed6.id,@tournament.id) + createMatch(@seed8.id,@seed3.id,@tournament.id) + elsif @bracket_size == 9 + createMatch(@seed7.id,@seed4.id,@tournament.id) + createMatch(@seed9.id,@seed5.id,@tournament.id) + createMatch(@seed8.id,@seed3.id,@tournament.id) + elsif @bracket_size == 8 + createMatch(@seed7.id,@seed4.id,@tournament.id) + createMatch(@seed8.id,@seed3.id,@tournament.id) + elsif @bracket_size == 7 + createMatch(@seed7.id,@seed4.id,@tournament.id) + end + + end + end + + end + + + + + + end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index db76c55..525e0cb 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -12,6 +12,7 @@ class TournamentsController < ApplicationController def show @schools = @tournament.schools @weights = @tournament.weights + @mats = @tournament.mats end # GET /tournaments/new @@ -26,6 +27,10 @@ class TournamentsController < ApplicationController # POST /tournaments # POST /tournaments.json def create + if user_signed_in? + else + redirect_to root_path + end @tournament = Tournament.new(tournament_params) respond_to do |format| if @tournament.save @@ -41,6 +46,10 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update + if user_signed_in? + else + redirect_to root_path + end respond_to do |format| if @tournament.update(tournament_params) format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } @@ -55,6 +64,10 @@ class TournamentsController < ApplicationController # DELETE /tournaments/1 # DELETE /tournaments/1.json def destroy + if user_signed_in? + else + redirect_to root_path + end @tournament.destroy respond_to do |format| format.html { redirect_to tournaments_url } diff --git a/app/controllers/weights_controller.rb b/app/controllers/weights_controller.rb index 906bdca..3aba682 100644 --- a/app/controllers/weights_controller.rb +++ b/app/controllers/weights_controller.rb @@ -21,16 +21,22 @@ class WeightsController < ApplicationController @tournament_field = params[:tournament] @tournament = Tournament.find(params[:tournament]) end + @mats = Mat.where(tournament_id: @tournament.id) end # GET /weights/1/edit def edit @tournament_field = @weight.tournament_id + @mats = Mat.where(tournament_id: @weight.tournament.id) end # POST /weights # POST /weights.json def create + if user_signed_in? + else + redirect_to root_path + end @weight = Weight.new(weight_params) @tournament = Tournament.find(weight_params[:tournament_id]) respond_to do |format| @@ -47,6 +53,10 @@ class WeightsController < ApplicationController # PATCH/PUT /weights/1 # PATCH/PUT /weights/1.json def update + if user_signed_in? + else + redirect_to root_path + end @tournament = Tournament.find(@weight.tournament_id) respond_to do |format| if @weight.update(weight_params) @@ -62,6 +72,10 @@ class WeightsController < ApplicationController # DELETE /weights/1 # DELETE /weights/1.json def destroy + if user_signed_in? + else + redirect_to root_path + end @tournament = Tournament.find(@weight.tournament_id) @weight.destroy respond_to do |format| @@ -78,6 +92,6 @@ class WeightsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def weight_params - params.require(:weight).permit(:max, :tournament_id) + params.require(:weight).permit(:max, :tournament_id, :mat_id) end end diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb index bc6c8ef..7e09100 100644 --- a/app/controllers/wrestlers_controller.rb +++ b/app/controllers/wrestlers_controller.rb @@ -43,6 +43,10 @@ class WrestlersController < ApplicationController # POST /wrestlers # POST /wrestlers.json def create + if user_signed_in? + else + redirect_to root_path + end @wrestler = Wrestler.new(wrestler_params) @school = School.find(wrestler_params[:school_id]) respond_to do |format| @@ -59,6 +63,10 @@ class WrestlersController < ApplicationController # PATCH/PUT /wrestlers/1 # PATCH/PUT /wrestlers/1.json def update + if user_signed_in? + else + redirect_to root_path + end @school = School.find(@wrestler.school_id) respond_to do |format| if @wrestler.update(wrestler_params) @@ -74,6 +82,10 @@ class WrestlersController < ApplicationController # DELETE /wrestlers/1 # DELETE /wrestlers/1.json def destroy + if user_signed_in? + else + redirect_to root_path + end @school = School.find(@wrestler.school_id) @wrestler.destroy respond_to do |format| diff --git a/app/helpers/mats_helper.rb b/app/helpers/mats_helper.rb new file mode 100644 index 0000000..00d3f97 --- /dev/null +++ b/app/helpers/mats_helper.rb @@ -0,0 +1,2 @@ +module MatsHelper +end diff --git a/app/models/mat.rb b/app/models/mat.rb new file mode 100644 index 0000000..7399548 --- /dev/null +++ b/app/models/mat.rb @@ -0,0 +1,4 @@ +class Mat < ActiveRecord::Base + belongs_to :tournament + has_many :weights, dependent: :destroy +end diff --git a/app/models/match.rb b/app/models/match.rb index d63c787..f5f8ffb 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,3 +1,4 @@ class Match < ActiveRecord::Base belongs_to :tournament + WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default"] end diff --git a/app/models/school.rb b/app/models/school.rb index dee553a..97585d0 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -3,11 +3,27 @@ class School < ActiveRecord::Base has_many :wrestlers, dependent: :destroy #calculate score here - #def score - # @score = 0 - # self.wrestlers.each do |w| - # @score = @score + w.season_win * 2 - # end - # self.score = @score - #end + def score + @score = 0 + self.wrestlers.each do |wrestler| + @match_wins = Match.where(winner_id: wrestler.id) + @match_wins.each do |m| + @score = @score + 2 + if m.win_type == "Major" + @score = @score + 1 + elsif m.win_type == "Tech Fall" + @score = @score + 1.5 + elsif m.win_type == "Pin" + @score = @score + 2 + elsif m.win_type == "Forfeit" + @score = @score + 2 + elsif m.win_type == "Injury Default" + @score = @score + 2 + elsif m.win_type == "Default" + @score = @score + 2 + end + end + end + self.score = @score + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 4b3c4ed..93f4ed5 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -2,5 +2,5 @@ class Tournament < ActiveRecord::Base has_many :schools, dependent: :destroy has_many :weights, dependent: :destroy has_many :matches, dependent: :destroy - + has_many :mats, dependent: :destroy end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 56fa9d4..6961cc7 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -7,7 +7,8 @@
  • <%= link_to "Home", root_path %>
  • <% if @tournament %>
  • <%= link_to "Brackets" , "/static_pages/weights?tournament=#{@tournament.id}" %>
  • -
  • <%= link_to "Bout Board" , '#' %>
  • +
  • <%= link_to "Upcoming Matches" , "/static_pages/up_matches?tournament=#{@tournament.id}" %>
  • +
  • <%= link_to "Results" , "/static_pages/results?tournament=#{@tournament.id}" %>
  • <% end %> <% if user_signed_in? %>
  • <%= link_to "Log Out", destroy_user_session_path, method: :delete %>
  • diff --git a/app/views/matches/_edit_form.html.erb b/app/views/matches/_edit_form.html.erb new file mode 100644 index 0000000..d66515b --- /dev/null +++ b/app/views/matches/_edit_form.html.erb @@ -0,0 +1,36 @@ +<%= form_for(@match) do |f| %> + <% if @match.errors.any? %> +
    +

    <%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:

    + + +
    + <% end %> + +
    + <%= f.label "Win Type" %>
    + <%= f.select(:win_type, Match::WIN_TYPES) %> +
    +
    + <%= f.label "Winner" %> Please put in the id of the winner
    + <%= @w1.name %> ID: <%= @w1.id %>
    + <%= @w2.name %> ID: <%= @w2.id %>
    + <%= f.number_field :winner_id %> +
    +
    + <%= f.label "Score" %> Also put pin time here if applicable. If default or forfeit, leave blank
    + <%= f.text_field :score %> +
    + + <%= f.hidden_field :finished, :value => 1 %> + <%= f.hidden_field :round, :value => @match.round %> + + +
    + <%= f.submit %> +
    +<% end %> diff --git a/app/views/matches/edit.html.erb b/app/views/matches/edit.html.erb index 38b7d70..a64773b 100644 --- a/app/views/matches/edit.html.erb +++ b/app/views/matches/edit.html.erb @@ -1,6 +1,5 @@ -

    Editing match

    +

    <%= @w1.name %> VS. <%= @w2.name %>

    -<%= render 'form' %> +<%= render 'edit_form' %> -<%= link_to 'Show', @match %> | -<%= link_to 'Back', matches_path %> +<%= link_to 'Back', root_path %> diff --git a/app/views/mats/_form.html.erb b/app/views/mats/_form.html.erb new file mode 100644 index 0000000..7c8d96b --- /dev/null +++ b/app/views/mats/_form.html.erb @@ -0,0 +1,31 @@ +<%= form_for(@mat) do |f| %> + <% if @mat.errors.any? %> +
    +

    <%= pluralize(@mat.errors.count, "error") %> prohibited this mat from being saved:

    + + +
    + <% end %> + +
    + <%= f.label :name %>
    + <%= f.text_field :name %> +
    + +<% if @tournament_field %> + <%= f.hidden_field :tournament_id, :value => @tournament_field %> +<% else %> +
    + <%= f.label 'Tournament' %>
    + <%= f.collection_select :tournament_id, Tournament.all, :id, :name %> +
    +<% end %> + +
    + <%= f.submit %> +
    +<% end %> diff --git a/app/views/mats/edit.html.erb b/app/views/mats/edit.html.erb new file mode 100644 index 0000000..08f73fc --- /dev/null +++ b/app/views/mats/edit.html.erb @@ -0,0 +1,6 @@ +

    Editing mat

    + +<%= render 'form' %> + +<%= link_to 'Show', @mat %> | +<%= link_to 'Back', mats_path %> diff --git a/app/views/mats/index.html.erb b/app/views/mats/index.html.erb new file mode 100644 index 0000000..13f4375 --- /dev/null +++ b/app/views/mats/index.html.erb @@ -0,0 +1,29 @@ +

    Listing mats

    + + + + + + + + + + + + + + <% @mats.each do |mat| %> + + + + + + + + <% end %> + +
    NameTournament
    <%= mat.name %><%= mat.tournament_id %><%= link_to 'Show', mat %><%= link_to 'Edit', edit_mat_path(mat) %><%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' } %>
    + +
    + +<%= link_to 'New Mat', new_mat_path %> diff --git a/app/views/mats/index.json.jbuilder b/app/views/mats/index.json.jbuilder new file mode 100644 index 0000000..a1d6780 --- /dev/null +++ b/app/views/mats/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@mats) do |mat| + json.extract! mat, :id, :name, :tournament_id + json.url mat_url(mat, format: :json) +end diff --git a/app/views/mats/new.html.erb b/app/views/mats/new.html.erb new file mode 100644 index 0000000..fb54f53 --- /dev/null +++ b/app/views/mats/new.html.erb @@ -0,0 +1,5 @@ +

    New mat

    + +<%= render 'form' %> + +<%= link_to 'Back', mats_path %> diff --git a/app/views/mats/show.html.erb b/app/views/mats/show.html.erb new file mode 100644 index 0000000..9fa0b69 --- /dev/null +++ b/app/views/mats/show.html.erb @@ -0,0 +1,13 @@ +

    <%= notice %>

    + +

    + Name: + <%= @mat.name %> +

    + +

    + Tournament: + <%= @mat.tournament_id %> +

    + +<%= link_to 'Edit', edit_mat_path(@mat) %> | diff --git a/app/views/mats/show.json.jbuilder b/app/views/mats/show.json.jbuilder new file mode 100644 index 0000000..fbf6872 --- /dev/null +++ b/app/views/mats/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @mat, :id, :name, :tournament_id, :created_at, :updated_at diff --git a/app/views/static_pages/_man10.html.erb b/app/views/static_pages/_man10.html.erb index a0dc68b..032d899 100644 --- a/app/views/static_pages/_man10.html.erb +++ b/app/views/static_pages/_man10.html.erb @@ -1,4 +1,4 @@ -

    <%= @weight.max %> lbs Bracket

    +

    Pool 1

    diff --git a/app/views/static_pages/_man7.html.erb b/app/views/static_pages/_man7.html.erb index 321a54f..22bf3f6 100644 --- a/app/views/static_pages/_man7.html.erb +++ b/app/views/static_pages/_man7.html.erb @@ -1,4 +1,3 @@ -

    <%= @weight.max %> lbs Bracket

    Pool 1

    diff --git a/app/views/static_pages/_man8.html.erb b/app/views/static_pages/_man8.html.erb index 882dfb3..eea6d5e 100644 --- a/app/views/static_pages/_man8.html.erb +++ b/app/views/static_pages/_man8.html.erb @@ -1,4 +1,3 @@ -

    <%= @weight.max %> lbs Bracket

    Pool 1

    diff --git a/app/views/static_pages/_man9.html.erb b/app/views/static_pages/_man9.html.erb index 1b2ff93..ca61b3d 100644 --- a/app/views/static_pages/_man9.html.erb +++ b/app/views/static_pages/_man9.html.erb @@ -1,4 +1,3 @@ -

    <%= @weight.max %> lbs Bracket

    Pool 1

    diff --git a/app/views/static_pages/brackets.html.erb b/app/views/static_pages/brackets.html.erb index b66c7f8..f1b493e 100644 --- a/app/views/static_pages/brackets.html.erb +++ b/app/views/static_pages/brackets.html.erb @@ -1,6 +1,7 @@ <%= link_to "Back to #{@tournament.name} weights", "/static_pages/weights?tournament=#{@tournament.id}" %>

    +

    <%= @weight.max %> lbs Bracket <%= Mat.find(@weight.mat_id).name %>

    <% if @bracket_size == 10 %> <%= render 'man10' %> <% elsif @bracket_size == 9 %> diff --git a/app/views/static_pages/generate_matches.html.erb b/app/views/static_pages/generate_matches.html.erb new file mode 100644 index 0000000..c5d6ff8 --- /dev/null +++ b/app/views/static_pages/generate_matches.html.erb @@ -0,0 +1,3 @@ +<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %> +
    +Done! \ No newline at end of file diff --git a/app/views/static_pages/results.html.erb b/app/views/static_pages/results.html.erb new file mode 100644 index 0000000..b8a2552 --- /dev/null +++ b/app/views/static_pages/results.html.erb @@ -0,0 +1,105 @@ +<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %> +
    +
    +

    Round 1

    +<% @matches.each do |m| %> + <% if m.round == 1 %> + <% if Wrestler.find(m.g_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.g_id) %> + <% else %> + <% @loser = Wrestler.find(m.g_id) %> + <% end %> + <% if Wrestler.find(m.r_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.r_id) %> + <% else %> + <% @loser = Wrestler.find(m.r_id) %> + <% end %> + <%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %> +
    + <% end %> +<% end %> +

    Round 2

    +<% @matches.each do |m| %> + <% if m.round == 2 %> + <% if Wrestler.find(m.g_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.g_id) %> + <% else %> + <% @loser = Wrestler.find(m.g_id) %> + <% end %> + <% if Wrestler.find(m.r_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.r_id) %> + <% else %> + <% @loser = Wrestler.find(m.r_id) %> + <% end %> + <%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %> +
    + <% end %> +<% end %> +

    Round 3

    +<% @matches.each do |m| %> + <% if m.round == 3 %> + <% if Wrestler.find(m.g_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.g_id) %> + <% else %> + <% @loser = Wrestler.find(m.g_id) %> + <% end %> + <% if Wrestler.find(m.r_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.r_id) %> + <% else %> + <% @loser = Wrestler.find(m.r_id) %> + <% end %> + <%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %> +
    + <% end %> +<% end %> +

    Round 4

    +<% @matches.each do |m| %> + <% if m.round == 4 %> + <% if Wrestler.find(m.g_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.g_id) %> + <% else %> + <% @loser = Wrestler.find(m.g_id) %> + <% end %> + <% if Wrestler.find(m.r_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.r_id) %> + <% else %> + <% @loser = Wrestler.find(m.r_id) %> + <% end %> + <%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %> +
    + <% end %> +<% end %> +

    Round 5

    +<% @matches.each do |m| %> + <% if m.round == 5 %> + <% if Wrestler.find(m.g_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.g_id) %> + <% else %> + <% @loser = Wrestler.find(m.g_id) %> + <% end %> + <% if Wrestler.find(m.r_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.r_id) %> + <% else %> + <% @loser = Wrestler.find(m.r_id) %> + <% end %> + <%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %> +
    + <% end %> +<% end %> +

    Round 6

    +<% @matches.each do |m| %> + <% if m.round == 6 %> + <% if Wrestler.find(m.g_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.g_id) %> + <% else %> + <% @loser = Wrestler.find(m.g_id) %> + <% end %> + <% if Wrestler.find(m.r_id).id == m.winner_id %> + <% @winner = Wrestler.find(m.r_id) %> + <% else %> + <% @loser = Wrestler.find(m.r_id) %> + <% end %> + <%= @winner.weight.max %> Lbs <%= @winner.name %> <%= m.win_type %> <%= m.score %> <%= @loser.name %> +
    + <% end %> +<% end %> diff --git a/app/views/static_pages/up_matches.html.erb b/app/views/static_pages/up_matches.html.erb new file mode 100644 index 0000000..e10b3ba --- /dev/null +++ b/app/views/static_pages/up_matches.html.erb @@ -0,0 +1,45 @@ +<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %> +
    +
    +

    Round 1

    +<% @matches.each do |m| %> + <% if m.round == 1 %> + <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %> +
    + <% end %> +<% end %> +

    Round 2

    +<% @matches.each do |m| %> + <% if m.round == 2 %> + <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %> +
    + <% end %> +<% end %> +

    Round 3

    +<% @matches.each do |m| %> + <% if m.round == 3 %> + <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %> +
    + <% end %> +<% end %> +

    Round 4

    +<% @matches.each do |m| %> + <% if m.round == 4 %> + <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %> +
    + <% end %> +<% end %> +

    Round 5

    +<% @matches.each do |m| %> + <% if m.round == 5 %> + <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %> +
    + <% end %> +<% end %> +

    Round 6

    +<% @matches.each do |m| %> + <% if m.round == 6 %> + <%= Wrestler.find(m.r_id).weight.max %> Lbs <%= @weight_class %> LBS <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <%= link_to "Control Match", "/matches/#{m.id}/edit" %> +
    + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 6871380..d1ab010 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -22,10 +22,13 @@ Director email: <%= @tournament.director_email %>

    +

    <% if user_signed_in? %> <%= link_to "New #{@tournament.name} School" , "/schools/new?tournament=#{@tournament.id}" %> +
    + BE CAREFUL <%= link_to "Generate Matches" , "/static_pages/generate_matches?tournament=#{@tournament.id}" %> <% end %>

    @@ -86,5 +89,35 @@
    +
    +
    +<% if user_signed_in? %> + <%= link_to "New #{@tournament.name} Mat" , "/mats/new?tournament=#{@tournament.id}" %> +<% end %> +
    +
    + + + + + + + + + + <% @mats.each do |mat| %> + + + + + <% end %> + +
    Name
    <%= mat.name %> + <% if user_signed_in? %> + <%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %> + <% end %> +
    + + diff --git a/app/views/weights/_form.html.erb b/app/views/weights/_form.html.erb index eabd963..39ff553 100644 --- a/app/views/weights/_form.html.erb +++ b/app/views/weights/_form.html.erb @@ -24,6 +24,13 @@ <%= f.collection_select :tournament_id, Tournament.all, :id, :name %> <% end %> + +
    + <%= f.label 'Assigned Mat' %>
    + <%= f.collection_select :mat_id, @mats, :id, :name %> + +
    +
    <%= f.submit %> diff --git a/config/routes.rb b/config/routes.rb index 109ffb4..3a94f13 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Wrestling::Application.routes.draw do + resources :mats + resources :matches devise_for :users @@ -20,8 +22,12 @@ Wrestling::Application.routes.draw do # You can have the root of your site routed with "root" root 'static_pages#index' get 'static_pages/brackets' - get 'static_pages/weights' + get 'static_pages/weights' get 'admin/index' + get 'static_pages/generate_matches' + get 'static_pages/up_matches' + get 'static_pages/control_match' + get 'static_pages/results' # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/db/migrate/20140125040820_add_tournament_id_to_matches.rb b/db/migrate/20140125040820_add_tournament_id_to_matches.rb new file mode 100644 index 0000000..cba7ed4 --- /dev/null +++ b/db/migrate/20140125040820_add_tournament_id_to_matches.rb @@ -0,0 +1,5 @@ +class AddTournamentIdToMatches < ActiveRecord::Migration + def change + add_column :matches, :tournament_id, :integer + end +end diff --git a/db/migrate/20140125062040_add_round_to_match.rb b/db/migrate/20140125062040_add_round_to_match.rb new file mode 100644 index 0000000..7cb1fdf --- /dev/null +++ b/db/migrate/20140125062040_add_round_to_match.rb @@ -0,0 +1,5 @@ +class AddRoundToMatch < ActiveRecord::Migration + def change + add_column :matches, :round, :integer + end +end diff --git a/db/migrate/20140125065007_create_mats.rb b/db/migrate/20140125065007_create_mats.rb new file mode 100644 index 0000000..8dadf67 --- /dev/null +++ b/db/migrate/20140125065007_create_mats.rb @@ -0,0 +1,10 @@ +class CreateMats < ActiveRecord::Migration + def change + create_table :mats do |t| + t.string :name + t.integer :tournament_id + + t.timestamps + end + end +end diff --git a/db/migrate/20140125065443_add_mat_id_to_weights.rb b/db/migrate/20140125065443_add_mat_id_to_weights.rb new file mode 100644 index 0000000..c04fdd6 --- /dev/null +++ b/db/migrate/20140125065443_add_mat_id_to_weights.rb @@ -0,0 +1,5 @@ +class AddMatIdToWeights < ActiveRecord::Migration + def change + add_column :weights, :mat_id, :integer + end +end diff --git a/db/migrate/20140125072649_add_finished_field_to_matches.rb b/db/migrate/20140125072649_add_finished_field_to_matches.rb new file mode 100644 index 0000000..493d314 --- /dev/null +++ b/db/migrate/20140125072649_add_finished_field_to_matches.rb @@ -0,0 +1,5 @@ +class AddFinishedFieldToMatches < ActiveRecord::Migration + def change + add_column :matches, :finished, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 09226d4..1ea46c0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140124174110) do +ActiveRecord::Schema.define(version: 20140125072649) do create_table "matches", force: true do |t| t.integer "r_id" @@ -23,6 +23,16 @@ ActiveRecord::Schema.define(version: 20140124174110) do t.string "score" t.datetime "created_at" t.datetime "updated_at" + t.integer "tournament_id" + t.integer "round" + t.integer "finished" + end + + create_table "mats", force: true do |t| + t.string "name" + t.integer "tournament_id" + t.datetime "created_at" + t.datetime "updated_at" end create_table "schools", force: true do |t| @@ -65,6 +75,7 @@ ActiveRecord::Schema.define(version: 20140124174110) do t.datetime "created_at" t.datetime "updated_at" t.integer "tournament_id" + t.integer "mat_id" end create_table "wrestlers", force: true do |t| diff --git a/test/controllers/mats_controller_test.rb b/test/controllers/mats_controller_test.rb new file mode 100644 index 0000000..7e43239 --- /dev/null +++ b/test/controllers/mats_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class MatsControllerTest < ActionController::TestCase + setup do + @mat = mats(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:mats) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create mat" do + assert_difference('Mat.count') do + post :create, mat: { name: @mat.name, tournament_id: @mat.tournament_id } + end + + assert_redirected_to mat_path(assigns(:mat)) + end + + test "should show mat" do + get :show, id: @mat + assert_response :success + end + + test "should get edit" do + get :edit, id: @mat + assert_response :success + end + + test "should update mat" do + patch :update, id: @mat, mat: { name: @mat.name, tournament_id: @mat.tournament_id } + assert_redirected_to mat_path(assigns(:mat)) + end + + test "should destroy mat" do + assert_difference('Mat.count', -1) do + delete :destroy, id: @mat + end + + assert_redirected_to mats_path + end +end diff --git a/test/fixtures/mats.yml b/test/fixtures/mats.yml new file mode 100644 index 0000000..56c2f39 --- /dev/null +++ b/test/fixtures/mats.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + tournament_id: 1 + +two: + name: MyString + tournament_id: 1 diff --git a/test/helpers/mats_helper_test.rb b/test/helpers/mats_helper_test.rb new file mode 100644 index 0000000..97340f0 --- /dev/null +++ b/test/helpers/mats_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MatsHelperTest < ActionView::TestCase +end diff --git a/test/models/mat_test.rb b/test/models/mat_test.rb new file mode 100644 index 0000000..dcb564d --- /dev/null +++ b/test/models/mat_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MatTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end