From 2e1f70803bf7a94de8574988d7cc390218e5fdee Mon Sep 17 00:00:00 2001 From: jcwimer Date: Mon, 16 Nov 2015 13:51:01 +0000 Subject: [PATCH] Advance wrestlers after teampointadjust in case its added after the last match in a pool. Also added coin flip tie breaker --- app/models/poolorder.rb | 7 +++++++ app/models/teampointadjust.rb | 4 ++++ app/models/wrestler.rb | 4 ++++ test/integration/pool_advancement_test.rb | 5 ++--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/poolorder.rb b/app/models/poolorder.rb index cd47672..4e88390 100644 --- a/app/models/poolorder.rb +++ b/app/models/poolorder.rb @@ -45,6 +45,7 @@ class Poolorder ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { headToHead } end ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints } + ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { coinFlip } end @@ -81,4 +82,10 @@ class Poolorder addPoints(wr) end end + + def coinFlip + wrestler = wrestlersWithSamePoints.sample + addPointsToWrestlersAhead(wrestler) + addPoints(wrestler) + end end \ No newline at end of file diff --git a/app/models/teampointadjust.rb b/app/models/teampointadjust.rb index 05f3934..ca2d708 100644 --- a/app/models/teampointadjust.rb +++ b/app/models/teampointadjust.rb @@ -1,3 +1,7 @@ class Teampointadjust < ActiveRecord::Base belongs_to :wrestler + + after_save do + self.wrestler.lastFinishedMatch.advance_wrestlers + end end diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index e106daa..772301a 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -10,6 +10,10 @@ class Wrestler < ActiveRecord::Base self.tournament.destroyAllMatches end + def lastFinishedMatch + allMatches.select{|m| m.finished == 1}.sort_by{|m| m.bout_number}.last + end + def totalDeductedPoints points = 0 self.deductedPoints.each do |d| diff --git a/test/integration/pool_advancement_test.rb b/test/integration/pool_advancement_test.rb index faba5d6..b307a34 100644 --- a/test/integration/pool_advancement_test.rb +++ b/test/integration/pool_advancement_test.rb @@ -59,13 +59,12 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest endMatch(1005,"Guy7",@matches) endMatch(2004,"Guy3",@matches) endMatch(2005,"Guy9",@matches) - #DEDUCT HAS TO HAPPEN BEFORE LAST MATCH IN POOL OR ELSE ITS NOT AVAILABLE FOR POOLORDER TO CHECK + endMatch(3004,"Guy7",@matches) + endMatch(3005,"Guy3",@matches) @deduct = Teampointadjust.new @deduct.wrestler_id = translateNameToId("Guy7") @deduct.points = 1 @deduct.save - endMatch(3004,"Guy7",@matches) - endMatch(3005,"Guy3",@matches) end def endMatch(bout,winner,matches)