diff --git a/app/models/generates_tournament_matches.rb b/app/models/generates_tournament_matches.rb index 401c5bf..6e71bbf 100644 --- a/app/models/generates_tournament_matches.rb +++ b/app/models/generates_tournament_matches.rb @@ -21,9 +21,19 @@ module GeneratesTournamentMatches end def generateMatches + moveFinalsMatchesToLastRound assignBouts assignLoserNames assignFirstMatchesToMats end + + def moveFinalsMatchesToLastRound + finalsRound = self.totalRounds + finalsMatches = self.matches.select{|m| m.bracket_position == "1/2" || m.bracket_position == "3/4" || m.bracket_position == "5/6" || m.bracket_position == "7/8"} + finalsMatches. each do |m| + m.round = finalsRound + m.save + end + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 5249631..f0ade0a 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -50,6 +50,6 @@ class Tournament < ActiveRecord::Base end def totalRounds - self.matches.sort_by{|m| m.bout_number}.last.round + self.matches.sort_by{|m| m.round}.last.round end end diff --git a/test/integration/pool_advancement_test.rb b/test/integration/pool_advancement_test.rb index d26b88f..f5c32da 100644 --- a/test/integration/pool_advancement_test.rb +++ b/test/integration/pool_advancement_test.rb @@ -9,7 +9,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest end def showMatches - matches = Match.where(weight_id: 5) + matches = Match.where(weight_id: 4) # matches = @matches.select{|m| m.weight_id == 4} matches.each do |m| puts "Bout: #{m.bout_number} #{m.w1_name} vs #{m.w2_name} #{m.bracket_position} #{m.poolNumber}" @@ -177,19 +177,19 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest def elevenManBracketToFinals elevenManBracketToSemis matches = @matches - endMatch(5006,"Guy11",matches) - endMatch(5007,"Guy12",matches) - endMatch(5008,"Guy16",matches) - endMatch(5009,"Guy17",matches) + endMatch(5004,"Guy11",matches) + endMatch(5005,"Guy12",matches) + endMatch(5006,"Guy16",matches) + endMatch(5007,"Guy17",matches) end def elevenManBracketFinished elevenManBracketToFinals matches = @matches - endMatch(6002,"Guy11",matches) - endMatch(6003,"Guy14",matches) - endMatch(6004,"Guy16",matches) - endMatch(6005,"Guy19",matches) + endMatch(6004,"Guy11",matches) + endMatch(6005,"Guy14",matches) + endMatch(6006,"Guy16",matches) + endMatch(6007,"Guy19",matches) end def endMatch(bout,winner,matches) @@ -457,5 +457,4 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest end - end diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb index 5895e04..573083d 100644 --- a/test/integration/poolbracket_matchups_test.rb +++ b/test/integration/poolbracket_matchups_test.rb @@ -248,5 +248,13 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest matches = @tournament.matches.order(:bout_number) assert_equal 'Mat1', matches.first.mat.name end + + test "finals matches in last round" do + lastRound = @tournament.totalRounds + finalsMatches = @tournament.matches.select{|m| m.bracket_position == "1/2" || m.bracket_position == "3/4" || m.bracket_position == "5/6" || m.bracket_position == "7/8"} + finalsMatches.each do |m| + assert_equal lastRound, m.round + end + end end