Skip to content
Browse files

Merge branch 'master' of github.com:wakeless/gallball

  • Loading branch information...
2 parents 7cd14c7 + dfc59ae commit 8f9906bdad30e16af40c974d35b10c3895d7bbca Michael Gall committed Apr 10, 2012
View
17 app/assets/stylesheets/leaderboard.css.scss
@@ -1,3 +1,20 @@
// Place all the styles related to the leaderboard controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
+
+#recent_games {
+ li {
+ margin-bottom: 8px;
+
+ span {
+ display: block;
+
+ &.time {
+ font-style: italic;
+ font-size: 12px;
+ line-height: 14px;
+ color: #999;
+ }
+ }
+ }
+}
View
5 app/assets/stylesheets/players.css.scss
@@ -1,3 +1,8 @@
// Place all the styles related to the players controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
+
+table#players {
+ width: 100%;
+ text-align: left;
+}
View
10 app/models/player.rb
@@ -30,4 +30,14 @@ def self.leaderboard(sport)
def games_played
games.length
end
+
+ def wins_hash
+ Hash[wins.group_by(&:loser_id).collect{|g| [g[0], g[1].length]}]
+ end
+
+ def bunny
+ if wins.length > 0 and wins_hash.values.max > (wins.length / 3) and wins_hash.values.max > 10
+ Player.find_by_id(wins_hash.key wins_hash.values.max)
+ end
+ end
end
View
8 app/views/layouts/application.html.erb
@@ -35,6 +35,7 @@
<ul class="nav">
<li><%= link_to "New Game", new_game_path %></li>
<li><%= link_to "Leaderboard", root_path %></li>
+ <li><%= link_to "Players", players_path %></li>
</ul>
</div><!--/.nav-collapse -->
</div>
@@ -49,10 +50,13 @@
</div>
<div class="span3">
<div class="well sidebar-nav">
- <ul class="nav nav-list">
+ <ul class="nav nav-list" id="recent_games">
<li class="nav-header">Recent Games</li>
<% @recent_games.each do |game| %>
- <li><%= game.to_s %></li>
+ <li>
+ <span><%= game.to_s %></span>
+ <span class="time"><%= time_ago_in_words(game.created_at) %> ago</span>
+ </li>
<% end %>
</ul>
</div><!--/.well -->
View
8 app/views/players/index.html.erb
@@ -1,8 +1,11 @@
<h1>Listing players</h1>
-<table>
+<table id="players">
<tr>
<th>Name</th>
+ <th>Wins</th>
+ <th>Losses</th>
+ <th>Bunny</th>
<th></th>
<th></th>
<th></th>
@@ -11,6 +14,9 @@
<% @players.each do |player| %>
<tr>
<td><%= player.name %></td>
+ <td><%= player.wins.length %></td>
+ <td><%= player.losses.length %></td>
+ <td><%= player.bunny.name if player.bunny %></td>
<td><%= link_to 'Show', player %></td>
<td><%= link_to 'Edit', edit_player_path(player) %></td>
<td><%= link_to 'Destroy', player, confirm: 'Are you sure?', method: :delete %></td>
View
17 spec/models/game_spec.rb
@@ -70,6 +70,23 @@
player2.ranks.first.value.should < 1000
}
end
+
+ describe "#update_player_rank_multiple" do
+ it {
+ sport = FactoryGirl.build(:sport, :name => '9ball')
+
+ player1 = FactoryGirl.create(:player)
+ player2 = FactoryGirl.create(:player)
+
+ (1..100).each do |i|
+ FactoryGirl.build(:game, :sport => sport, :winner => player1, :loser => player2).update_player_rank
+ FactoryGirl.build(:game, :sport => sport, :winner => player2, :loser => player1).update_player_rank
+ end
+
+ player1.ranks.first.value.should > 950
+ player2.ranks.first.value.should > 950
+ }
+ end
describe "#after_save" do
it {

0 comments on commit 8f9906b

Please sign in to comment.
Something went wrong with that request. Please try again.