Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix counters

  • Loading branch information...
commit 4cf95376816c79ea6dd09a56c827836e8581cd6c 1 parent 4ebb1ef
@aserafin aserafin authored
Showing with 6 additions and 4 deletions.
  1. +2 −0  app/models/match.rb
  2. +4 −4 app/models/player.rb
View
2  app/models/match.rb
@@ -3,6 +3,8 @@ class Match < ActiveRecord::Base
has_one :score
has_many :competitors
+ scope :confirmed, -> { where(state: :confirmed) }
+
state_machine :state, initial: :pending do
after_transition on: :finished, do: :send_confirmation_email
View
8 app/models/player.rb
@@ -17,18 +17,18 @@ def setup_default_rating
end
def count_matches(tournament)
- matches.where(tournament_id: tournament.id).count
+ matches.confirmed.where(tournament_id: tournament.id).count
end
def count_wins(tournament)
- matches.where('tournament_id = ? and winners @> ARRAY[?]', tournament.id, self.id).count
+ matches.confirmed.where('tournament_id = ? and winners @> ARRAY[?]', tournament.id, self.id).count
end
def count_losts(tournament)
- matches.where('tournament_id = ? and not (winners @> ARRAY[?])', tournament.id, self.id).count
+ matches.confirmed.where('tournament_id = ? and (array_length(winners, 1) > 0 and not (winners @> ARRAY[?]))', tournament.id, self.id).count
end
def count_draws(tournament)
- matches.where('tournament_id = ? and array_length(winners, 1) = 0', tournament.id).count
+ matches.confirmed.where('tournament_id = ? and array_length(winners, 1) = 0', tournament.id).count
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.