Skip to content

Commit

Permalink
Fix #35: incorrect ranking and broken leaderboard after first game fo…
Browse files Browse the repository at this point in the history
…llowing a reset.
  • Loading branch information
dblock committed Oct 6, 2015
1 parent e1bf444 commit f652dc9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-10-06 11:38:17 -0400 using RuboCop version 0.34.2.
# on 2015-10-06 13:22:25 -0400 using RuboCop version 0.34.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -28,20 +28,20 @@ Lint/RescueException:
Exclude:
- 'config.ru'

# Offense count: 20
# Offense count: 21
Metrics/AbcSize:
Max: 37

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 117
Max: 118

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 246
# Offense count: 250
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 209
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Changelog

* [#35](https://github.com/dblock/slack-gamebot/issues/35): Fix: missing ranking and broken leaderboard in first game after reset - [@dblock](https://github.com/dblock).
* [#34](https://github.com/dblock/slack-gamebot/issues/34): Fix: `season` incorrectly reports no seasons after reset - [@dblock](https://github.com/dblock).
* Fix: correctly handle `user_change` event - [@dblock](https://github.com/dblock).
* [#29](https://github.com/dblock/slack-gamebot/issues/29): Fix: `season` incorrectly reports number of players - [@dblock](https://github.com/dblock).
Expand Down
1 change: 1 addition & 0 deletions slack-gamebot/models/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def lose!(loser, scores = nil)
Match.create!(challenge: self, winners: winners, losers: losers, scores: scores)
winners.inc(wins: 1)
losers.inc(losses: 1)
User.rank!
update_attributes!(state: ChallengeState::PLAYED)
end

Expand Down
1 change: 1 addition & 0 deletions spec/fabricators/match_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
after_create do |match|
match.winners.inc(wins: 1)
match.losers.inc(losses: 1)
User.rank!
challenge.update_attributes!(state: ChallengeState::PLAYED, updated_by: match.losers.first)
end
end
15 changes: 11 additions & 4 deletions spec/models/season_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
expect(User.all.detect { |u| u.wins != 0 || u.losses != 0 }).to be nil
end
it 'saves user ranks' do
expect(season.user_ranks.count).to eq 4
expect(season.user_ranks.count).to eq 6
end
it 'to_s' do
expect(season.to_s).to eq "#{season.created_at.strftime('%F')}: #{season.send(:winner).user_name}: 1 win, 0 losses (elo: 48), 3 matches, 4 players"
expect(season.to_s).to eq "#{season.created_at.strftime('%F')}: #{season.send(:winner).user_name}: 1 win, 0 losses (elo: 48), 3 matches, 6 players"
end
end
context 'without challenges' do
Expand All @@ -28,11 +28,18 @@
expect(season.errors.messages).to eq(challenges: ['No matches have been recorded.'])
end
end
context 'current season' do
context 'current season with one match' do
let!(:match) { Fabricate(:match) }
let(:season) { Season.new }
it 'to_s' do
expect(season.to_s).to eq "Current: #{season.send(:winner).user_name}: 1 win, 0 losses (elo: 48), 1 match, 2 players"
end
end
context 'current season with multiple matches' do
let!(:matches) { 3.times.map { Fabricate(:match) } }
let(:season) { Season.new }
it 'to_s' do
expect(season.to_s).to eq "Current: #{season.send(:winner).user_name}: 1 win, 0 losses (elo: 48), 3 matches, 4 players"
expect(season.to_s).to eq "Current: #{season.send(:winner).user_name}: 1 win, 0 losses (elo: 48), 3 matches, 6 players"
end
context 'with an unplayed challenge' do
before do
Expand Down

0 comments on commit f652dc9

Please sign in to comment.