From d065e31818ee587cdff03b39da1612098887dd73 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Thu, 28 May 2015 12:24:46 +0000 Subject: [PATCH] Loser name generation was not saving. Fixed that and added a test. --- app/models/generates_loser_names.rb | 8 +++++++- test/integration/poolbracket_matchups_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/generates_loser_names.rb b/app/models/generates_loser_names.rb index 7ac2d30..023eb12 100644 --- a/app/models/generates_loser_names.rb +++ b/app/models/generates_loser_names.rb @@ -10,8 +10,8 @@ module GeneratesLoserNames elsif w.pool_bracket_type == "fourPoolsToSemi" fourPoolsToSemiLoser(matches_by_weight) end + saveMatches(matches_by_weight) end - return matches_by_weight end def twoPoolsToSemiLoser(matches_by_weight) @@ -54,4 +54,10 @@ module GeneratesLoserNames seventhEighth.loser1_name = "Loser of #{consoSemis.select{|m| m.bracket_position_number == 1}.first.bout_number}" seventhEighth.loser2_name = "Loser of #{consoSemis.select{|m| m.bracket_position_number == 2}.first.bout_number}" end + + def saveMatches(matches) + matches.each do |m| + m.save! + end + end end diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb index 37db1c7..93cd62e 100644 --- a/test/integration/poolbracket_matchups_test.rb +++ b/test/integration/poolbracket_matchups_test.rb @@ -131,5 +131,13 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest end end + test "test loser name for 16 man bracket 3/4th place match" do + @matches = @tournament.matches.where(weight_id: 5) + @semi_bouts = @matches.where(bracket_position: 'Semis') + @third_fourth_match = @matches.where(bracket_position: '3/4').first + assert_equal "Loser of #{@semi_bouts.first.bout_number}", @third_fourth_match.loser1_name + end + #todo test crazy movements through each bracket? + end