Permalink
Browse files

merge master

  • Loading branch information...
2 parents 0e1421e + 199086d commit 3be31ca92648f5ea2b40dd9614cd7982aa554601 @aserafin aserafin committed Jan 3, 2014
Showing with 6 additions and 5 deletions.
  1. +2 −1 app/controllers/matches_controller.rb
  2. +4 −4 app/models/player.rb
View
3 app/controllers/matches_controller.rb
@@ -1,4 +1,5 @@
class MatchesController < InheritedResources::Base
+ before_filter :authenticate_player!
def confirm
match = Match.finished.where(id: params[:id]).first
@@ -9,7 +10,7 @@ def confirm
end
redirect_to root_path
- end
+ end
def create
build_resource.save
View
8 app/models/player.rb
@@ -17,18 +17,18 @@ def setup_default_rating
end
def count_matches(tournament)
- matches.confirmed.where(tournament_id: tournament.id).count('distinct match_id')
+ @count_matches ||= matches.confirmed.where(tournament_id: tournament.id).count('distinct match_id')
end
def count_wins(tournament)
- matches.confirmed.where('tournament_id = ? and winners @> ARRAY[?]', tournament.id, self.id).count('distinct match_id')
+ @count_wins ||= matches.confirmed.where('tournament_id = ? and winners @> ARRAY[?]', tournament.id, self.id).count('distinct match_id')
end
def count_losts(tournament)
- matches.confirmed.where('tournament_id = ? and (coalesce(array_length(winners, 1), 0) > 0 and not (winners @> ARRAY[?]))', tournament.id, self.id).count('distinct match_id')
+ @count_losts ||= matches.confirmed.where('tournament_id = ? and (array_length(winners, 1) > 0 and not (winners @> ARRAY[?]))', tournament.id, self.id).count('distinct match_id')
end
def count_draws(tournament)
- matches.confirmed.where('tournament_id = ? and coalesce(array_length(winners, 1), 0) = 0', tournament.id).count('distinct match_id')
+ count_matches(tournament) - (count_losts(tournament) + count_wins(tournament))
end
end

0 comments on commit 3be31ca

Please sign in to comment.